错误:' < '标记前预期的非限定id
Error: expected unqualified-id before ‘<’ token
我正在尝试制作某种模板化的Queue
类。这似乎是可以的,但我得到2个错误在同一行,我不知道为什么。错误出现在实现文件。cpp中,我试图给出析构函数的定义。下面是类的头文件的代码:
#ifndef QUEUETP_H_INCLUDED
#define QUEUETP_H_INCLUDED
template <class T>
class QueueTp
{
private:
struct Node { T item; struct Node * next;};
enum {QSIZE = 10};
//Queue's head
Node *head;
//Queue's tail
Node *tail;
int size;
int maxsize;
QueueTp(const QueueTp & q);
QueueTp & operator=(const QueueTp & q) { return *this;}
public:
QueueTp(): size(0),head(0),tail(0),maxsize(QSIZE) {};
QueueTp(int q = QSIZE): size(0),head(0),tail(0),maxsize(q) {};
~QueueTp();
bool isEmpty(){return size==0;}
bool isFull() {return size==maxsize;}
int sizecur() {return size;}
bool push(const T& t);
bool pop(T& t);
};
#include "QueueTp.cpp"
#endif // QUEUETP_H_INCLUDED
下面是析构函数在实现文件中的定义:
#include "QueueTp.h"
#include <iostream>
using namespace std;
typename <class T> //<-<-<- in this line I am getting the two errors
QueueTp<class T>::~QueueTp()
{
Node *ptr;
cout<<endl<<"Deleting the queue...";
while (head !=NULL)
{
ptr = head->next;
delete head;
head = ptr;
}
}
//......other method definitions
错误在上面,我从编译器得到的具体错误消息在下面。
error: expected nested-name-specifier before ‘<’ token|
error: expected unqualified-id before ‘<’ token|
||=== Build finished: 2 errors, 12 warnings ===||
请使用"template"而不是"typename"在你得到两个错误消息的行!我发现大多数时候,一个未识别的关键字或一个真正的关键字在错误的地方经常会给出类似于未定义类型的错误,它后面的下一个符号会导致错误。
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 方法内部但循环仍得到预期的不合格id错误C++
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 错误:令牌 { '{' 之前应存在非限定 ID
- DCMTK 了解"DIMSE 没有有效的演示上下文 ID"错误
- C++中的"expected unqualified-id"错误是什么?
- c++ for 循环中预期的非限定 id 错误
- 在"." 令牌之前应为非限定 ID(C++ 错误)
- 预期"{"错误?以及预期的未指定 ID 错误?
- 错误:预期的非限定 ID 错误:含义和修复
- 安卓-NDK-R7C "deque.h"中的非限定 ID 错误
- 预期的不合格id错误,很可能是原因
- 意外的非限定 ID 错误
- C++中类出现预期的不合格id错误
- 出现意外的非限定id错误
- iOS中出现不合格的id错误
- XSLT到HTML的转换.Qt5中的generate-id()错误
- 不合格的id错误和井字游戏板不工作
- 传递结构体数组的预期非限定id错误
- 如何执行项目范围内的唯一id /错误代码,以便在源代码中轻松找到错误的来源