C ++模板typedef
我有一堂课
template<size_t N, size_t M>
class Matrix {
// ....
};
我想做一个typedef ,它创建一个Vector (列向量),它相当于一个大小为N和1的Matrix 。类似的东西:
typedef Matrix<N,1> Vector<N>;
这会产生编译错误。 以下创建类似的东西,但不完全是我想要的:
template <int N>
class Vector: public Matrix<N,1>
{ };
是否有解决方案或不太昂贵的解决方法/最佳实践?
C ++ 11添加了别名声明,它们是typedef泛化,允许模板:
template <size_t N>
using Vector = Matrix<N, 1>;
类型Vector<3>等同于Matrix<3, 1> 。
在C ++ 03中,最接近的是:
template <size_t N>
struct Vector
{
typedef Matrix<N, 1> type;
};
这里, Vector<3>::type等同于Matrix<3, 1> 。
上一篇: C++ template typedef
