July 18, 1998

A static class member

A class member declared static is a single instance of that member shared by all instances of this class (that’s why it is sometimes termed a class variable, as opposed to object variable). This feature has many uses: for instance, in order to create a file lock, one can use

Placement new

Operator new allocates memory from the heap, on which an object is constructed. Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount (there’s no

Namespace aliases

Choosing a short name for a namespace can eventually lead to a name clash. On the other hand, very long namespaces are not easy to use. For that purpose, namespace aliases can be used: //file decl.hnamespace Excel_Software_Company { class Date {/*..*/};class Time {/*..*/};//…other declarations }//file calendar.cpp#include “decl.h”void main(){namespace ESC =

Avoid using double underscore in your identifiers

Identifiers starting with __ (double underscore) are reserved for C/C++ implementations and standard libraries. Furthermore, C++ programs are transformed by the compiler (inline substitution, addition of this as an argument to a non-static member function and creation of temporary objects – to name a few). As a result, new identifiers

Prefer Standard Library’s containers to hand-made ones

Before implementing containers such list, vector, queue, stack etc., by yourself, you can cut costs and software shipment time significantly by using The Standard Template Library, or STL. STL defines the following types of containers: vector, list, deque (double-ended queue), queue, stack, map, set and bitset – all of them