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.
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