Item 9: Never call virtual functions during construction or destruction
- make sure that none of your constructors or destructors call virtual functions on the object being created or destroyed and that all the functions they call obey the same constraint
- ? ? having derived classes pass necessary construction information up to base class constructors (not sure that last solution example)
Item 10: Have assignment operators return a reference to *this
class WidgetItem 11: Handle assignment to self in operator=
{
public:
...
Widget& operator=(const Widget& rhs) // return type is a reference to
{ // the current class
...
return *this; // return the left-hand object
}
...
};
Need to read the later chapters together.
Item 12: Copy all parts of an object
- if you add a data member to a class, you need to make sure that you update the copying functions, too.
- every PriorityCustomer also contains a copy of the data members it inherits from Customer, and those data members are not being copied at all
- Read the last several paragraphs
if you're releasing resources manually, you're doing something wrong. Pre-canned resource-managing classes like auto_ptr and tr1::shared_ptr often make following this Item's advice easy
No comments:
Post a Comment