Not*_*ist 356 c++ templates typedef c++11
我上课了
template<size_t N, size_t M>
class Matrix {
// ....
};
Run Code Online (Sandbox Code Playgroud)
我想typedef
创建一个Vector
(列向量),它相当于一个Matrix
大小为N和1的东西.这样的东西:
typedef Matrix<N,1> Vector<N>;
Run Code Online (Sandbox Code Playgroud)
这会产生编译错误.以下内容创建了类似的内容,但并不完全符合我的要求:
template <size_t N>
class Vector: public Matrix<N,1>
{ };
Run Code Online (Sandbox Code Playgroud)
是否有解决方案或不太昂贵的解决方法/最佳实践?
GMa*_*ckG 532
C++ 11添加了别名声明,它是一般化typedef
,允许模板:
template <size_t N>
using Vector = Matrix<N, 1>;
Run Code Online (Sandbox Code Playgroud)
类型Vector<3>
相当于Matrix<3, 1>
.
在C++ 03中,最接近的近似值是:
template <size_t N>
struct Vector
{
typedef Matrix<N, 1> type;
};
Run Code Online (Sandbox Code Playgroud)
这里,类型Vector<3>::type
相当于Matrix<3, 1>
.
归档时间: |
|
查看次数: |
156113 次 |
最近记录: |