I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes:
Expand|Select|Wrap|Line Numbers
- #include <stack>
- template <class T>
- class A
- {
- public:
- // constructor
- A(const T &zz): z(zz) {}
- T z;
- // nested class
- class B
- {
- public:
- // constructor
- B(const T &xx, const T &yy): x(xx), y(yy) {}
- T x;
- T y;
- };
- };
- template <class T>
- class Iter
- {
- public:
- Iter(const T &xx): x(xx) {}
- T x;
- std::stack< A<T> > aStack;
- std::stack< A<T>::B > bStack;
- };
Expand|Select|Wrap|Line Numbers
- #include "nested.H"
- int main(int argc, char *argv[])
- {
- A<int> myAObject(5);
- A<int>::B myBOjbect(6,7);
- Iter<int> myIterObject(2);
- return 0;
- }
nested.H:44: error: type/value mismatch at argument 1 in template parameter list for ‘template<cla\
ss _Tp, class _Sequence> class std::stack’
nested.H:44: error: expected a type, got ‘A<T>::B’
nested.H:44: error: template argument 2 is invalid
As you can see, it doesn't know what to do with A<T>::B in the stack declaration of the templated class Iter. How do I reference this nested class within Iter? Obviously, I can do it in main as shown above. Many thanks.
-David