简体   繁体   English

使用不带arg列表的类模板(未声明的标识符)

[英]Using class template without arg list (undeclared identifier)

I am new to class templates and am having trouble. 我是班级模板的新手,遇到了麻烦。 I have a function that doesn't declare (ie. to be an int, double etc). 我有一个未声明的函数(即为int,double等)。 But it doesn't make sense to declare in this function. 但是在此函数中声明没有任何意义。 Therefore I am getting errors. 因此,我遇到了错误。 Thanks for the help. 谢谢您的帮助。

I have the following function: 我有以下功能:

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

This returns the following errors: 这将返回以下错误:

Error 1 error C2065: 'ItemType' : undeclared identifier Error 2 error C2955: 'QueType' : use of class template requires template argument list 错误1错误C2065:'ItemType':未声明的标识符错误2错误C2955:'QueType':使用类模板需要模板参数列表
Error 3 error C2509: 'IsEmpty' : member function not declared in 'QueType' 错误3错误C2509:“ IsEmpty”:成员函数未在“ QueType”中声明

I think you're looking for: 我认为您正在寻找:

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

在函数声明之前添加template <typename ItemType>

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

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