一段代码(1),来自maplab

看源码看到下面这段,解释一下:

template<typename Type, typename ... Arguments>

inline std::shared_ptr<Type> aligned_shared(Arguments&&... arguments)

{

typedef typename std::remove_const<Type>::type TypeNonConst;

//首先std::remove_const<Type>::type TypeNonConst:就是,如果Type有定义const类型,则TypeNonConst与Type同类型但是去掉const,否则与Type完全一样。(从定义的名字上也能很好的理解)

//typename std::remove_const<Type>::type TypeNonConst:加上typename的目的是告诉编译器std::remove_const<Type>::type是类型,因为在模板实例化前,鬼晓得std::remove_const<Type>是什么东东。

//所以对于有模板类型的变量,要想重命名,就要用typedef + typename

return std::allocate_shared<Type>(Eigen::aligned_allocator<TypeNonConst>(),std::forward<Arguments>(arguments)...);

}

猜你喜欢

转载自blog.csdn.net/ynshi57/article/details/88543411