Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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.

like image 429
Paul Kinpzz Avatar asked Feb 09 '23 19:02

Paul Kinpzz


1 Answers

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.

like image 125
Paul Kinpzz Avatar answered Feb 11 '23 08:02

Paul Kinpzz