【问题标题】:C++ Class and Function Template declarations?C++ 类和函数模板声明?
【发布时间】:2014-07-09 00:25:03
【问题描述】:

现在我正在尝试让我的模板类和函数运行,但我不确定如何定义模板 void 函数。下面是我的一小部分代码。该代码不会运行,并且在任何时候使用类 arrayList 时都会显示argument list for arrayList is missing

#include <iostream>
using namespace std;

template<typename Type> //Template class declaration 
class arrayList
{
public:
    void print() const;

protected:
    int *list;                          //array to hold the list elements
    int length;                         //to store the length of the list
    int maxSize;                        //to store the maximum size of the list
};

template<typename Type>
void arrayList::print() const
{
    int i;

    for(i = 0; i < length; i++)
        cout<<list[i]<<" ";
    cout<<endl;
}

【问题讨论】:

  • 您帖子的哪一部分代表了“最小可编译示例”中的最小

标签: c++ function templates


【解决方案1】:

试试

template<typename Type>
void arrayList<Type>::print() const ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    相关资源
    最近更新 更多