I'm trying to learn templates 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 can't figure out 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 looks like the definition of the function causes the error, but I don't know why I get this error, it looks OK to me (even if I guess it's not really OK), just a syntax error perhaps?..
I compile with clang++ -Wall -Werror -Wextra -c.
What could cause this error?
You need to specify the template parameter for it, since myClass
is a class template.
template<typename T>
myClass<T>::myClass(void) : std::stack<T>() {
// ^^^
}
LIVE
BTW: : std::stack<T>()
seems to be redundant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With