The default copy constructor basically invokes the copy constructor of each member, unless it's a built-in type (int, double, pointers, etc), in which case the underlying bytes are simply copied into the member. In the case of pointers that are "managed" by the object this can be disastrous, as multiple objects are then prone to "free" the object.
Originally Posted by micahharwell
So...yes, you generally need to write your own copy constructor in such a case (or else use a "smart-pointer", or similar).
foo( void )
data = new int;
~foo( void )
std::cout << "foo (" << static_cast< void* >( this ) << ") freeing data (" << data << ")" << std::endl;
int main( void )
foo a, b = a;