sluki
sluki

Reputation: 605

Nested type as template parameter of base class

Is it possible?

example:

template<class T>
class A {};

class B : public A<B::C>
{
public:
  struct C {};
};

Problem is that B::C is undeclared identifier (which is obvious why) and I don't know how to make it work. In summary: Can B derive from A with template parameter set to C?

Upvotes: 9

Views: 403

Answers (1)

dom0
dom0

Reputation: 7486

No. B is incomplete at this point, because you have not yet defined the class it should inherit from. Thus it is not possible to reference B::C here (nested classes/structs depend on the complete definition of their enclosing class/struct, since the nested type could and often does depend on the definition of the enclosing one).

Upvotes: 8

Related Questions