我写了一个名为的课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;
};
Run Code Online (Sandbox Code Playgroud)
看来.cpp文件中有错误:
MyQueue.cpp:17:1:'MyQueue'不是类,命名空间或枚举
我不知道什么是错的,但是当我将模板更改为时
#define Queue_entry int
Run Code Online (Sandbox Code Playgroud)
它可以成功运行.
在问我的同学时,我知道它应该是
template <class Queue_entry>
MyQueue<Queue_entry>::MyQueue() {}
Run Code Online (Sandbox Code Playgroud)
所以这个问题就解决了.我应该记住格式.
| 归档时间: |
|
| 查看次数: |
5439 次 |
| 最近记录: |