Is it possible for subclasses to share the same template? For example:
template <class T>
class A
{
private:
T _aObj;
public:
class B
{
public:
T _bObj;
};
};
Where T can be used in both A and B?
When I’ve tried this, I get the following error:
error: A::B is not a template
Yes that works fine (on a standards-complying compiler).
A way of thinking why this is logical is because
Bis not simply part ofA, it is part ofA<T>!Tis not only part of the type forA, but also forB(the correct name for it would beA<T>::B.)