我是类模板的新手,遇到了麻烦。我有一个未声明的函数(即是一个 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/