c++ - 使用不带参数列表的类模板(未声明的标识符)

标签 c++ templates data-structures

我是类模板的新手,遇到了麻烦。我有一个未声明的函数(即是一个 int、double 等)。但是在这个函数中声明是没有意义的。因此我收到错误。感谢您的帮助。

我有以下功能:

bool QueType<ItemType>::IsEmpty() const
// Returns true if there are no elements on the queue and false otherwise.
{
    return (front == NULL);
}

这将返回以下错误:

错误 1 ​​错误 C2065:“ItemType”:未声明的标识符 错误 2 错误 C2955:“QueType”:使用类模板需要模板参数列表
错误 3 error C2509: 'IsEmpty': 成员函数未在 'QueType' 中声明

最佳答案

我认为您正在寻找:

template <typename ItemType>
bool QueType<ItemType>::IsEmpty() const
// Returns true if there are no elements on the queue and false otherwise.
{
    return (front == NULL);
}

关于c++ - 使用不带参数列表的类模板(未声明的标识符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12714602/

相关文章:

arrays - 使用哈希表检查数组中是否有重复项

c++ - 解决 C++ 中的最小交换 hackerrank 问题

c++ - 运算符重载 C++ +=

c++ - 将字符串转换为二维数组

c++ - 二叉搜索树中序迭代器 C++

c++ - 不能使用一个类的成员 typedef 作为模板特化定义中的模板参数

templates - Handlebars.js if block 助手 ==

c++ - 为什么要使用专门的模板类?

c++ - 为什么在4GB的虚拟内存空间上只能分配2GB?

c++ - 内存优化结构cpp