c++类和函数模板声明

C++ Class and Function Template declarations?

本文关键字:声明 函数模板 c++      更新时间:2023-10-16

现在我正试图使我的模板类和函数运行,但我不确定如何定义模板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;
}

Try

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