Item 54: Familiarize yourself with the standard library, including TR1
Item.55: Familiarize yourself with Boost.
ED2:
Item 3: Prefer
new and delete to malloc and free. The problem with
malloc and free (and their variants) is simple: they don't know about constructors and destructor.string *stringArray1 = static_cast(malloc(10 * sizeof(string)));
string *stringArray2 = new string[10];
stringArray1 points to enough memory for 10 string objects, but no objects have been constructed in that memory. In contrast, stringArray2 points to an array of 10 fully constructed string objects, each of which can safely be used in any operation taking a string.
Item 4: Prefer C++-style commentsItem 44: Say what you mean; understand what you're saying.
- A common base class means common traits. If class
D1and classD2both declare classBas a base,D1andD2inherit common data members and/or common member functions fromB. - Public inheritance means is-a. If class
Dpublicly inherits from classB, every object of typeDis also an object of typeB, but not vice versa - Layering means has-a or is-implemented-in-terms-of. If class
Acontains a data member of typeB, objects of typeAeither have a component of typeBor are implemented in terms of objects of typeB - A pure virtual function means that only the function's interface is inherited. If a class
Cdeclares a pure virtual member functionmf, subclasses ofCmust inherit the interface formf, and concrete subclasses ofCmust supply their own implementations for it. - A simple virtual function means that the function's interface plus a default implementation is inherited. If a class
Cdeclares a simple (not pure) virtual functionmf, subclasses ofCmust inherit the interface formf, and they may also inherit a default implementation, if they choose. - A nonvirtual function means that the function's interface plus a mandatory implementation is inherited. If a class
Cdeclares a nonvirtual member functionmf, subclasses ofCmust inherit both the interface formfand its implementation. In effect,mfdefines an invariant over specialization ofC.

No comments:
Post a Comment