C
chuan
I define a class with a private dynamical member
Class A
{
double *data;
public:
A();
~A();
}
In constructor I assign a block memory to data,
A::A(){
data = new double [size];
}
and delete it in the desturctor
A::~A(){
delete [] data;
}
So far so good, but when I trying to overload some arithmetic operator
(+ or /),
I receive the "glibc detected: double free or corruption" error. Here
is my code
A A:perator+(A add){
A tmp;
for (int i=0; i<size; i++)
tmp = this->data + add.data;
return tmp;
}
Please give me a hint.
Class A
{
double *data;
public:
A();
~A();
}
In constructor I assign a block memory to data,
A::A(){
data = new double [size];
}
and delete it in the desturctor
A::~A(){
delete [] data;
}
So far so good, but when I trying to overload some arithmetic operator
(+ or /),
I receive the "glibc detected: double free or corruption" error. Here
is my code
A A:perator+(A add){
A tmp;
for (int i=0; i<size; i++)
tmp = this->data + add.data;
return tmp;
}
Please give me a hint.