C++ template typedef

前端 未结 1 897
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 08:30

I have a class

template
class Matrix {
    // ....
};

I want to make a typedef which creates a

相关标签:
1条回答
  • 2020-11-22 08:53

    C++11 added alias declarations, which are generalization of typedef, allowing templates:

    template <size_t N>
    using Vector = Matrix<N, 1>;
    

    The type Vector<3> is equivalent to Matrix<3, 1>.


    In C++03, the closest approximation was:

    template <size_t N>
    struct Vector
    {
        typedef Matrix<N, 1> type;
    };
    

    Here, the type Vector<3>::type is equivalent to Matrix<3, 1>.

    0 讨论(0)
提交回复
热议问题