O'Reilly logo
  • wenbo yang thinks this is interesting:

It can also lead to resource management complications: if the base class stores a pointer to the matrix data, but that data may have been either dynamically allocated or physically stored inside the derived class object (as we saw), how will it be determined whether the pointer should be deleted? Such questions have answers, but the more sophisticated you try to be about them, the more complicated things become. At some point, a little code replication begins to look like a mercy.

From

Cover of Effective C++: 55 Specific Ways to Improve Your Programs and Designs, Third Edition

Note

hmmm, but it already stores a pointer in above example, doesn’t it?

-Not the same thing, here base class will be the only owner of this pointer, but the resource is allocated in derived class, this is not good. We prefer to have the same owner for allocation and free of resource.