Problems with "Barton Nackman Trick"

M

Michael Lehn

I want to use the "Barton Nackman trick" for my matrix hierarchy. But I ran
into a problem with a typedef I need in the base class:

template <typename E>
class Matrix
{
public:
typedef typename E::TT TT;

};

template <typename T>
class DenseMatrix : public Matrix<DenseMatrix<T> >
{
public:
typedef T TT;

};

this gives the error: no type named `TT' in `class DenseMatrix<double>'

Is there a chance to solve this problem, or is it even a comipler problem?

I think the approach is pretty useless if this doesn't work. Most (or even
all) methods in the base class will depend on the parameter "E::TT".
 
M

Michael Lehn

Michael said:
I want to use the "Barton Nackman trick" for my matrix hierarchy. But I
ran into a problem with a typedef I need in the base class:

template <typename E>
class Matrix
{
public:
typedef typename E::TT TT;

};

template <typename T>
class DenseMatrix : public Matrix<DenseMatrix<T> >
{
public:
typedef T TT;

};

this gives the error: no type named `TT' in `class DenseMatrix<double>'

Is there a chance to solve this problem, or is it even a comipler problem?

I think the approach is pretty useless if this doesn't work. Most (or
even all) methods in the base class will depend on the parameter "E::TT".

hmmm, this seems to work:

template <typename A>
struct Traits
{
};

template <typename E>
class Matrix
{
public:
typedef typename Traits<E>::TT TT;

};

template <typename T>
class DenseMatrix : public Matrix<DenseMatrix<T> >
{
public:
typedef T TT;

};

template <typename T>
struct Traits<DenseMatrix<T> >
{
typedef T TT;
};


....is this a bug or a feature?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top