Sunday, February 28, 2010

Static Declaration

Given: static class A {int i;} X;A a; Then: 'a' is not static. Note: X is static.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 55.

Friday, February 26, 2010

Inlined Free Functions

You can declare a free function to be inline.

Wednesday, February 24, 2010

References to Constants

The following compiles: const int &i = 12;
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 112.

Monday, February 22, 2010

Implicit Pointer Conversions

Implicit conversions of 'pointers to members' are in the opposite direction of implicit conversions of 'pointers to classes'.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 122.

Saturday, February 20, 2010

Pass by Value

An argument passed by value to a function is passed by initialization and not by assignment.
Reference: "C++ Gotchas" by Stephen Dewhurst. Addison-Wesley, 2002., p. 126.

Thursday, February 18, 2010

Copy Assignment Operator

A derived class cannot inherit the copy assignment operator from its base class.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 132

Tuesday, February 16, 2010

Copy Constructor

A compiler-generated implicit copy constructor uses assignment instead of initialization for copying pointers, enums, and built-in types; whereas it uses initialization for copying non-scalar user-defined types.
Reference: "C++ Gotchas" by Stephen C. Dewhurst, Addison-Wesley, 2002., p. 133.

Monday, February 15, 2010

Member Initialization List

Arrays and static data members cannot be initialized in a member initialization list (MIL).
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 141.

Friday, February 12, 2010

Static Downcasts

It is illegal to do a static downcast from a virtual base class to a derived class.
Reference: "C++ Gotchas" by Stephen C. Dewhurst, Addison-Wesley, 2002., p. 146.

Wednesday, February 10, 2010

External Linkage

The following have external linkage:
1. static data members
2. static member functions
3. non-static member functions
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 163.

Monday, February 8, 2010

Array and Vector Delete

'array delete' destroys elements in reverse order of its initialization, while when a vector is destroyed, its elements are destroyed from first to last.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 168.

Saturday, February 6, 2010

Placement new

You can replace 'operator new', but you cannot replace 'placement new'.
Reference: "C++ Gotchas" by Stephen C. Dewhurst, Addison-Wesley, 2002., p. 174

Thursday, February 4, 2010

Virtual Functions

A public virtual function declared in a base class can be overridden as a private virtual function in a derived class.
Reference: "C++ Gotchas" by Stephen C. Dewhurst. Addison-Wesley, 2002., p. 227.

Tuesday, February 2, 2010

Function Signature

The return type is not a part of a function's signature, but its constness is.
Reference: "C++ Gotchas" by Stephen C., Dewhurst, Addison-Wesley, 2002., p. 228.