Tuesday, March 30, 2010

Visitor Design Pattern

The Visitor Pattern has two class hierarchies, Visitor and Element.
Only the Visitor hierarchy can change a lot without causing a maintenance burden.

Reference: Pattern Hatching by John Vlissides, Addison-Wesley, 1998., p. 37.

Monday, March 29, 2010

Private Destructor

A class cannot be subclassed if its destructor is private.
Reference: Pattern Hatching by John Vlissides, Addison-Wesley, 1998., p. 40.

Friday, March 26, 2010

Private Members

A very not nice way to get access to private members is to put '#define private public' before the header file #include of the class you want to access the private members of.
Reference: Pattern Hatching by John Vlissides, Addison-Wesley, 1998., p. 47.

Wednesday, March 24, 2010

Abstract Classes

Besides pure virtual functions, another way to make a class abstract is to make the constructors protected.

Reference: Pattern Hatching: Design Patterns Applied by John Vlissides, Addison-Wesley, 1998., p. 113.

Monday, March 22, 2010

References to Arrays

A pointer to an array does not preserve the array bound information, but a reference to an array does.

Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 12.

Saturday, March 20, 2010

Conditional Operator

The result of the conditional operator (?:) is an lvalue.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 15.

Thursday, March 18, 2010

Arrays

parray[-4] could be a valid expression, if parray is of type: 'int *'.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 16.