this is really stupid of me but the compiler shows error sayin that add function is not declared. When i remove the pointer from the argument of add...Test* add(Test p)....with the corresponding changes it works normally. From the code segments that are commented u ll know wat i want ultimately. but i m stuck at this point itself.
#include<iostream.h>
#include<conio.h>
class Test{
private:
int a;
public:
Test(int k){
a=k;
}
Test* operator +(Test *p){
int d=this->a+p->geta();
Test *temp=new Test(d);
return temp;
}
Test* add(Test *p){
int d=this->a+p->geta();
Test *temp=new Test(d);
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);
int k=sum(2,4);
Test *h=t1.add(t2);
//Test *z=sum(t1,t2);
cout<<k<<endl<<h->geta();
getch();
}
Um... do you mind writing in standard english? Or at least, do it like me and try to. Wrtn liek thiz doesn't only make it hard to read, it also makes you look stupid.