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
D1
and classD2
both declare classB
as a base,D1
andD2
inherit common data members and/or common member functions fromB
. - Public inheritance means is-a. If class
D
publicly inherits from classB
, every object of typeD
is also an object of typeB
, but not vice versa - Layering means has-a or is-implemented-in-terms-of. If class
A
contains a data member of typeB
, objects of typeA
either have a component of typeB
or are implemented in terms of objects of typeB
- A pure virtual function means that only the function's interface is inherited. If a class
C
declares a pure virtual member functionmf
, subclasses ofC
must inherit the interface formf
, and concrete subclasses ofC
must 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
C
declares a simple (not pure) virtual functionmf
, subclasses ofC
must 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
C
declares a nonvirtual member functionmf
, subclasses ofC
must inherit both the interface formf
and its implementation. In effect,mf
defines an invariant over specialization ofC
.
No comments:
Post a Comment