1

Can someone please clarify inner class use with templates? I have searched through books and internet examples to learn templates but few examples show inner class usage. What I gathered so far is

template <class T>
class A
{
     class B
     {
         B()
         ~B()
     }

     A();
     ~A();

    B* a(T i, B* l);
}

From reading this and this I believe I should define outer class constructor as

template <class T>
class A<T>::A()
{

}

but how am I defining the inner class constructor definition? How do I define the definition of a? I have struggled with this for most of the day trying to figure this out and really appreciate assistance.

Mushy
  • 2,395
  • 9
  • 31
  • 53

1 Answers1

2

You shouldn't use class in the definition of the constructor of A, it should be

template <class T>
A<T>::A()
{
}

And for the constructor of B,

template <class T>
A<T>::B::B()
{
}

And for the member function a, use typename when refers to A<T>::B

template <class T>
typename A<T>::B* A<T>::a(T i, typename A<T>::B* l)
{
    return ...;
}

LIVE

songyuanyao
  • 163,662
  • 15
  • 289
  • 382