C ++模板typedef - C++ template typedef

語言: CN / TW / HK

問題:

I have a class 我有一堂課

template<size_t N, size_t M>
class Matrix {
    // ....
};

I want to make a typedef which creates a Vector (column vector) which is equivalent to a Matrix with sizes N and 1. Something like that: 我想做一個typedef來創建一個Vector (列向量),它等效於大小為N和1的Matrix

typedef Matrix<N,1> Vector<N>;

Which produces compile error. 產生編譯錯誤。 The following creates something similar, but not exactly what I want: 以下創建類似的東西,但不完全是我想要的東西:

template <size_t N>
class Vector: public Matrix<N,1>
{ };

Is there a solution or a not too expensive workaround / best-practice for it? 是否有解決方案或不太昂貴的解決方法/最佳實踐?


解決方案:

參考一: http://stackoom.com/question/Bj71
參考二: C++ template typedef
「其他文章」