简体   繁体   中英

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

I have written a class named Queue . When I try to build the project, I get a compile-time error.

The .h file:

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;
};

It appears there's an error in the .cpp file:

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

I don't know what's wrong, but when I change the template to

#define Queue_entry int

it can be run successfully.

When asking my classmate I Know it should be

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

So this problem is solved. I should remember the format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM