Can't get this one to work right. Help.

Here is the code that won't seem to work. The errors are below.

#include <iostream>
#include <algorithm>

using namespace std;

template <class T, int n>
class ONE
{
private: T x[n];
public: void Read();
template <class T, int n>
void Display(ONE <T, n> p);
~ONE();
};

int main()
{
ONE <char, 4> p;
cout << "Enter 4 characters: ";
p.Read();
ONE<int, 5> q;
cout << "Enter 5 integers: ";
q.Read();
cout << "This is array x of object p in sorted form: ";
p.SortArray();
p.Display();
cout << "This is array x of object q in sorted form: ";
q.SortArray();
q.Display();

return 0;
}
template <class T, int n>
void ONE<T, n>::Read()
{
for (int i = 0; i < n; ++i)
cin >> x[i];
}
template <class T, int n>
void ONE<T,n>::Display()
{
for (int i = 0; i < n; ++i) { cout << x[i] << ' '; }cout << endl;
}
template <class T, int n>
void ONE<T,n>::SortArray()
{
sort(x, x + n);
}
template <class T, int n>
ONE<T, n> :: ~ONE(){}

ERRORS:
7 IntelliSense: class "ONE<char, 4>" has no member "SortArray" c:\Users\LESTER\Desktop\Visual Studio\Project 10\Project 10\No 4.cpp 33 4 Project 10
9 IntelliSense: class "ONE<int, 5>" has no member "SortArray" c:\Users\LESTER\Desktop\Visual Studio\Project 10\Project 10\No 4.cpp 36 4 Project 10
8 IntelliSense: no instance of function template "ONE<T, n>::Display [with T=char, n=4]" matches the argument list
object type is: ONE<char, 4> c:\Users\LESTER\Desktop\Visual Studio\Project 10\Project 10\No 4.cpp 34 3 Project 10
10 IntelliSense: no instance of function template "ONE<T, n>::Display [with T=int, n=5]" matches the argument list
object type is: ONE<int, 5> c:\Users\LESTER\Desktop\Visual Studio\Project 10\Project 10\No 4.cpp 37 3 Project 10
Error 1 error C2039: 'SortArray' : is not a member of 'ONE<char,4>' c:\users\lester\desktop\visual studio\project 10\project 10\no 4.cpp 33 1 Project 10
Error 2 error C2780: 'void ONE<char,4>::Display(ONE<T,n>)' : expects 1 arguments - 0 provided c:\users\lester\desktop\visual studio\project 10\project 10\no 4.cpp 34 1 Project 10
Error 3 error C2039: 'SortArray' : is not a member of 'ONE<int,5>' c:\users\lester\desktop\visual studio\project 10\project 10\no 4.cpp 36 1 Project 10
Error 4 error C2780: 'void ONE<int,5>::Display(ONE<T,n>)' : expects 1 arguments - 0 provided c:\users\lester\desktop\visual studio\project 10\project 10\no 4.cpp 37 1 Project 10
Error 5 error C2244: 'ONE<T,n>::Display' : unable to match function definition to an existing declaration c:\users\lester\desktop\visual studio\project 10\project 10\no 4.cpp 51 1 Project 10
Error 6 error C2039: 'SortArray' : is not a member of 'ONE<T,n>' c:\users\lester\desktop\visual studio\project 10\project 10\no 4.cpp 56 1 Project 10
> class "ONE<char, 4>" has no member "SortArray"
you are trying to use a function that does not exist
(you have defined a function in line 45, but never declared it inside your class)

> no instance of function template "ONE<T, n>::Display
you've said that 'Display' takes one parameter, so you ought to provide one parameter
If that parameter would never be used, then don't put it in the parameter list.


PS: [code]"Please use code tags"[/code]
Topic archived. No new replies allowed.