hi people,
i am able to make the following code work if i don't use a destructor:
#include<iostream>
using namespace std;
class CVector{
public:
int *x, *y;
CVector();
CVector operator+ (CVector);
CVector(int,int);
// ~CVector();
private:
};
CVector::CVector(){
x = new int;
y = new int;
*x=0;
*y=0;
}
CVector::CVector(int a, int b){
x = new int;
y = new int;
*x = a;
*y = b;
}
CVector CVector::operator+ (CVector param){
CVector temp;
*(temp.x) = *x + *(param.x);
*(temp.y) = *y + *(param.y);
return temp;
}
/*
CVector::~CVector(){
delete x;
delete y;
}
*/
int main(){
CVector a(3,1);
CVector b(1,2);
CVector c;
c=a+b;
cout << *(c.x) << ", " << *(c.y);
return 0;
}
but when i uncomment the destructor.. i face problems.
am i missing something?
thanks.
avpy(the newbie)