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.
- 7. Templates and Generic Programming
- from Effective C++: 55 Specific Ways to Improve Your Programs and Designs, Third Edition
- Publisher: Addison-Wesley Professional
- Released: May 2005
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.
Share this highlighthttp://www.safaribooksonline.com/a/effective-c-55/2036776/