Is it possible for C++ subclasses to share the same template?

c++, nested-class, scope, templates

Solution

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`.)

Problem

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

Original source