Error: Use of class template requires template argument list

c++, class, templates

Solution

Members of a template class are themselves templates parameterized by the parameters of their template class. When such a member is defined outside its class, it must explicitly be declared a template.

So you need change

void FOURTEEN::ReadData()

to

template <class T, int n>
void FOURTEEN<T, n>::ReadData()

And do the same thing to function `DisplayData`.

And there're some other errors:

In function `ReadData`, change

cin>>a.[i];

to

cin>>a[i];

and In function `DisplayData`, change

cin>>a.[i]<<'\t';

to

cout<<a[i]<<'\t';

Problem

When I try to run my program this error shows up "error C2955: 'FOURTEEN' : use of class template requires template argument list" ``` #include <iostream> using namespace std; template <class T, int n> class FOURTEEN { private: T a[n]; public: void ReadData(); void DisplayData(); }; void FOURTEEN::ReadData() { for(int i=0;i<n;++i) cin>>a.[i]; } void FOURTEEN::DisplayData() { for(int i=0;i<n;++i) cin>>a.[i]<<'\t'; cout<<endl; } int main() { FOURTEEN <int, 5>P; //Read data into array a of object P cout<<"Enter 5 numbers: "; P.ReadData(); //display data of array a of object P P.DisplayData(); system("pause"); return 0; } ``` Do I have to retype template somewhere else?

Original source