C
Chris Foster
Hi, I'm having some difficulty using types which are defined in a base
class inside a derived class. The problem crops up using template
classes.
The following test code encapsulates what I'd like to do, but doesn't
compile with g++ (v3.3.3).
//---------------------------------------------------------
// A = base class
template <typename T>
class A
{
public:
enum Aenum {foo, bar};
};
// B = class derived from A; inherits type A<T>::Aenum.
template <typename T>
class B : public A<T>
{
public:
Aenum ae;
B(Aenum ae)
{
this->ae = ae;
}
};
//---------------------------------------------------------
When I try to compile, g++ complains with the errors
templtest.cpp:19: warning: `B<T>::Aenum' is implicitly a typename
templtest.cpp:19: warning: implicit typename is deprecated, please see
the documentation for details
templtest.cpp:21: warning: `B<T>::Aenum' is implicitly a typename
templtest.cpp:21: warning: implicit typename is deprecated, please see
the documentation for details
If instead I explicitly tell the compiler that Aenum is a type,
defining the class B by:
//---------------------------------------------------------
template <typename T>
class B : public A<T>
{
public:
typename A<T>::Aenum ae;
B(typename A<T>::Aenum ae = foo)
{
this->ae = ae;
}
};
//---------------------------------------------------------
then the compilation goes without a problem. However, it seems as
though the compiler has all the information it could need to determine
that Aenum is a type from the original definition. Certinally if we
define Aenum within the derived class B rather than the base class A
then there's no problem.
So my question is: is this the behaviour that we *should* expect from
g++, and if so, why?
class inside a derived class. The problem crops up using template
classes.
The following test code encapsulates what I'd like to do, but doesn't
compile with g++ (v3.3.3).
//---------------------------------------------------------
// A = base class
template <typename T>
class A
{
public:
enum Aenum {foo, bar};
};
// B = class derived from A; inherits type A<T>::Aenum.
template <typename T>
class B : public A<T>
{
public:
Aenum ae;
B(Aenum ae)
{
this->ae = ae;
}
};
//---------------------------------------------------------
When I try to compile, g++ complains with the errors
templtest.cpp:19: warning: `B<T>::Aenum' is implicitly a typename
templtest.cpp:19: warning: implicit typename is deprecated, please see
the documentation for details
templtest.cpp:21: warning: `B<T>::Aenum' is implicitly a typename
templtest.cpp:21: warning: implicit typename is deprecated, please see
the documentation for details
If instead I explicitly tell the compiler that Aenum is a type,
defining the class B by:
//---------------------------------------------------------
template <typename T>
class B : public A<T>
{
public:
typename A<T>::Aenum ae;
B(typename A<T>::Aenum ae = foo)
{
this->ae = ae;
}
};
//---------------------------------------------------------
then the compilation goes without a problem. However, it seems as
though the compiler has all the information it could need to determine
that Aenum is a type from the original definition. Certinally if we
define Aenum within the derived class B rather than the base class A
then there's no problem.
So my question is: is this the behaviour that we *should* expect from
g++, and if so, why?