views:

151

answers:

1

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 Matrix<N,1> Vector<N>;

Which produces compile error. The following creates something similar, but not exactly what I want:

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

Is there a solution or a not too expensive workaround / best-practice for it? Thanks in advance!

+13  A: 

Most will recommend:

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

Use as:

typedef Vector<3>::type vector3;

C++0x will add this ability:

template <int N>
using Vector<N> = Matrix<N,1>;
GMan
Oh great, I hadn't seen this part of C++0x and I've been bitching about templated typedef for a while... guess I should have a more thorough read of the final draft.
Matthieu M.