C ++ when using the template <class T> error: .. is not a class

I am writing a queue class. But when I use mac osx to create my project, I encounter some problem. WHEN h file likes:

template<class Queue_entry> class MyQueue { public: MyQueue(); bool empty() const; // add entry in the tail of the queue Error_code append(Queue_entry &x); // throw the entry of the front Error_code serve(); // get the front entry of the queue Error_code retrieve(Queue_entry &x) const; protected: Queue_entry entry[MAXQUEUE]; int count; int front, rear; }; 

An error appears in the cpp file. Error:

 MyQueue.cpp:17:1: 'MyQueue' is not a class, namespace, or enumeration 

I do not know how this happens. But when I change the template to

 #define Queue_entry int 

It can be successfully executed.

+5
source share
1 answer

When I ask my classmate, I know what it should be

 template <class Queue_entry> MyQueue<Queue_entry>::MyQueue() {} 

So this problem is resolved. I have to remember the format.

+6
source

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


All Articles