I have removed all the unwanted segments. I am trying to pass pointers to an overloaded operator and use templates too. But this is still not working.
#include<iostream.h>
#include<conio.h>
class Test{
private:
int a;
public:
Test (){}
Test(int k){
a=k;
}
Test* operator +(Test *p){
Test *temp=new Test(this->a+p->geta());
return temp;
}
int geta(){
return a;
}
};
template<class T>
T* sum(T* a,T* b){
return a+b;
}
int main(){
Test *t1,*t2;
t1=new Test(5);
t2=new Test(7);
Test *z=sum(t1,t2);
cout<<z->geta();
getch();
}
Firstly,
t1is a pointer, and you are calling theaddmethod incorrectly – should bet1->add(t2). Secondly, thesum()methods takes arguments which are not pointers, i.e. the template parameter is deduced asTestrather thanTest*, hence you need to change the signature to something like: