You are being a bit unfair to the compiler here - C
is incomplete without B<C>
fully known and when processing B<C>
, C
is 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.:
struct C : B<C> {
void f() { typedef typename C::Asub Asub; }
};
You could work around the problem by either passing the types explicitly upward:
template<class T, class Asub> struct B { /* ... */ };
class C : B<C, int> { /* ... */ };
... or by moving them to some traits class if you need to pass more:
template<class T, class Traits> struct B {
void DoSomething(typename Traits::Asub it) {}
};
struct CTraits {
typedef int Asub;
};
struct C : B<C, CTraits> {
typedef CTraits::Asub Asub;
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…