Hello
i'm trying to solve an exersice i've been given , would appreciate help
i have to creat a class with two templates
and in the main make an array of that class but it keeps poping the error 2955
the exersice says i can't overload :perator[]
any ideas ?
here's what i've for so far
//Pair.h
template<class T,class S>
class Pair
{
protected:
T rison;
S sheni;
public:
Pair(T mfirst,S msecond);
virtual ~Pair();
T first(){return rison;};
S second(){return sheni;};
};
//Pair.cpp
template<class T,class S>
Pair<T,S>::Pair(T mfirst,S msecond)
{
this->rison=mfirst;
this->sheni=msecond;
cout <<"Pair has been created "<<endl;
}
template<class T,class S>
Pair<T,S>::~Pair()
{
cout <<"Pair has been deleted "<<endl;
}
//main
#include "Pair.h"
#include "Find.h"
const int SIZE=5;
void main()
{
double n1;
char* n2;
Pair* arr;
arr = new Pair [SIZE];
for (int i=0;i<SIZE<i++)
{
cout <<"Enter two values "<<endl;
cout <<"----->";
cin >>n1;
n2 = new char[SIZE];
cin >>n2;
arr[i]->Pair(n1,n2);
}
delete [] arr;
delete [] n2;
}
Now I know I can do this by declaring
in the class Pair
T* rishon
S* sheni
and overloading the operator[]
but i need to decalre the Pair* arr in the main and somehow
create it
Anyone ?
thanks in advance



LinkBack URL
About LinkBacks
perator[]



