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 B
is not simply part of A
, it is part of A<T>
! T
is not only part of the type for A
, but also for B
(the correct name for it would be A<T>::B
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With