0

I have a nested class inside a template class and wish to implement its constructor outside of the scope. However, I get the following error:

expected unqualified-id before ')' token

template<class T>
class mainClass {
private:
    class nestedClass {
    public:
        nestedClass();
    };
};

template<class T>
typename mainClass<T>::nestedClass::nestedClass(){
    // code here
}
Guy Waldman
  • 457
  • 3
  • 12

2 Answers2

0

Remove the typename:

template<class T>
mainClass<T>::nestedClass::nestedClass(){
    // code here
}

Live Demo

For more info on in which contexts we need to use typename see here.

Community
  • 1
  • 1
101010
  • 41,839
  • 11
  • 94
  • 168
  • It doesn't work. I think it must have a typename for the compiler to realize that nestedClass is a type and not something else (e.g. a static variable or a function). – Guy Waldman Jun 07 '16 at 20:17
0

It seems my problem concerned another bug which I had not noticed up until now. In any regard, it is true that typename was not required in the context in which it was used.

Thank you.

Guy Waldman
  • 457
  • 3
  • 12