The following code does not compile.
I get an error message: error C2039: ‘Asub’ : is not a member of ‘C’
Can someone help me to understand this?
Tried VS2008 & 2010 compiler.
template <class T>
class B
{
typedef int Asub;
public:
void DoSomething(typename T::Asub it)
{
}
};
class C : public B<C>
{
public:
typedef int Asub;
};
class A
{
public:
typedef int Asub;
};
int _tmain(int argc, _TCHAR* argv[])
{
C theThing;
theThing.DoSomething(C::Asub());
return 0;
}
You are being a bit unfair to the compiler here –
Cis incomplete withoutB<C>fully known and when processingB<C>,Cis still an incomplete type. There are similar threads on comp.lang.c++.moderated and comp.lang.c++.Note that it works if you delay the use by moving it into a member function definition, e.g.:
You could work around the problem by either passing the types explicitly upward:
… or by moving them to some traits class if you need to pass more: