我写了一个名为Queue
的类。当我尝试构建项目时,出现编译时错误。
.h
文件:
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;
};
.cpp
文件中出现错误:
MyQueue.cpp:17:1:'MyQueue'不是类,命名空间或枚举
我不知道什么是错的,但当我将模板更改为
时#define Queue_entry int
它可以成功运行。
答案 0 :(得分:6)
当问我的同学时,我知道它应该是
template <class Queue_entry>
MyQueue<Queue_entry>::MyQueue() {}
所以这个问题就解决了。我应该记住格式。