简体   繁体   English

使用模板时的c ++ <class T> 错误:..不是一个类

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

I have written a class named Queue . 我写了一个名为Queue的类。 When I try to build the project, I get a compile-time error. 当我尝试构建项目时,出现编译时错误。

The .h file: .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;
};

It appears there's an error in the .cpp file: 似乎.cpp文件中存在错误:

MyQueue.cpp:17:1: 'MyQueue' is not a class, namespace, or enumeration MyQueue.cpp:17:1:'MyQueue'不是类,命名空间或枚举

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. 我应该记住格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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