×
רמי
Hey,
I've created a small class that overrides the "+" operator, and
defines a destructor:
private:
T *data;
int size;
public:
myClass(int s);
myClass<T> operator+(const myClass<T>& vec);
~myClass();
The implementation of the operator is:
myClass<T> myClass<T>:
perator+(const myClass<T>& cls)
{
int i;
myClass<T> res(cls.size);
for (i=0;i<cls.size;i++)
{
res.data = data;
}
return res;
}
Don't judge the code as its just a pseudo of the real one that.
The destructor is:
myClass<T>::~myClass()
{
delete [] data;
}
The problem is, that after the last line of the operator+ - "return
res"
I don't know why, but the destructor is called for "res",
Which means that the object returned, is already cleaned!!!
What am I missing\doing wrong?
Thanks ahead
--sternr
I've created a small class that overrides the "+" operator, and
defines a destructor:
private:
T *data;
int size;
public:
myClass(int s);
myClass<T> operator+(const myClass<T>& vec);
~myClass();
The implementation of the operator is:
myClass<T> myClass<T>:
{
int i;
myClass<T> res(cls.size);
for (i=0;i<cls.size;i++)
{
res.data = data;
}
return res;
}
Don't judge the code as its just a pseudo of the real one that.
The destructor is:
myClass<T>::~myClass()
{
delete [] data;
}
The problem is, that after the last line of the operator+ - "return
res"
I don't know why, but the destructor is called for "res",
Which means that the object returned, is already cleaned!!!
What am I missing\doing wrong?
Thanks ahead
--sternr