Michael Bullock
Michael Bullock

Reputation: 994

How to typedef an inner class

I have a matrix class and a column class inside it:

template<class T>
struct MatrixT
{
    template<class T>
    struct ColumnT
    {
    };
};

Note that a ColumnT will always hold the same type as a MatrixT.

For convenience I define

typedef MatrixT<double> matrix;

Since in reality, I'll be using a double element most of the time. But I also want to define something similar for the columnT class. I tried

typedef MatrixT<double>::ColumnT<double> matrix::column;

but compilation fails with the error

Error - qualified name is not allowed

Is there a way of achieving what I want?

I'd like to be able to type matrix::column c; just as I can type matrix m;

Upvotes: 1

Views: 244

Answers (1)

Not a real meerkat
Not a real meerkat

Reputation: 5729

Just remove the second template<class T>

template<class T>
struct MatrixT
{
    struct ColumnT
    {
    };
};

ColumnT should then be using the same type as MatrixT, and your typedef...

typedef MatrixT<double> matrix;

...should work as you are expecting it to.

Upvotes: 2

Related Questions