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
}
1
  • Remove the typename.
    – LogicStuff
    Jun 7, 2016 at 20:14

2 Answers 2

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.

1
  • 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). Jun 7, 2016 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.