Template and derived class definition: Error: "myClass" is not a class, namespace, or enumeration

I am trying to learn patterns in C ++ and I have the following code:

#include <stack> template<typename T> class myClass : public std::stack<T>{ public: myClass(void); myClass(myClass const & src); virtual ~myClass(void); myClass & operator=(myClass const & rhs); }; template<typename T> myClass::myClass(void) : std::stack<T>(){ } 

But I cannot understand why I get the following when I try to compile:

 test.cpp:17:1: error: 'myClass' is not a class, namespace, or enumeration myClass::myClass(void) : std::stack<T>(){ ^ test.cpp:8:9: note: 'myClass' declared here class myClass : public std::stack<T>{ ^ 1 error generated. 

It seems that the definition of the function is causing an error, but I donโ€™t know why I get this error, it looks normal to me (even if I assume that it is not completely normal), maybe a syntax error ?.

I am compiling with clang ++ -Wall -Werror -Wextra -c .

What can cause this error?

+5
source share
1 answer

You need to specify a template parameter for it, since myClass is a template class.

 template<typename T> myClass<T>::myClass(void) : std::stack<T>() { // ~~~ } 

BTW : std::stack<T>() seems redundant.

Live

+8
source

Source: https://habr.com/ru/post/1240656/


All Articles