Originally Posted by
Codeplug
If A doesn't have an overloaded equals operator (and copy constructor) then you could be performing shallow copies of A, which would be bad if A is calling delete in it's destructor.
Here's a program entitled "When Shallow Copy'n Goes Wrong".
Run it, it should be educational...
Code:
#include <iostream>
using namespace std;
class A
{
char *str;
public:
A()
{
str = new char[100];
cout << "constructor - new 0x"
<< hex << (int)str << dec << endl;
}//constuctor
~A()
{
cout << "destructor - delete 0x"
<< hex << (int)str << dec << endl << flush;
delete[] str;
}//destructor
};//A
int main()
{
A a, b;
a = b;
return 0;
}//main
>> what debugger?
gdb
gg