User:Feixie/C++/MoreEffectiveC++

More effective C++ prefix increment and suffix increment (x++ and ++x) T& operator++; const T operator++(int); 	//const avoid x++++;

never overload &&,||,',', because you can't maintain their side effects &&,||	short cut circuit ','		evaluate left, then right, return right.

difference between throw an exception and pass a parameter
 * thrown exception aways be copied. (catching by value causes it to be copied twice)
 * catch's parameter can be only converted:
 * from derive class to base class (pointer)
 * to void* (match all)

exception specification unexpected will be invoked if function itself explicitly throw unmatched exception.

assist named return value initializaiton to eliminate temporary variables T func {	int c = ....; return T(c);	// construct on return; }

cost of
 * virtual function
 * virtual table for each class
 * virtual pointer for each obj
 * indirect virtual function call
 * multi-inheritance
 * virtual inheritance (side effect: virtual base's ctor is invoked by the most derived class)
 * RTTI (make use of virtual table)

virtualize ctor and non-member function
 * factory patten
 * dispatch with the help of virtual member function

forbid creating obj on heap (make operator new/delete as protected) forbid creating obj on stack (make destructor as private, constructor public, and add a function to delete itself) check if pointer is pointed to obj on heap (make use of the position of heap and stack, take care of data segement) check if pointer is pointed to obj on stack (make use of stack is growing down wards)

diff between operator new and new operator

smart pointer SmartPointer --> RefernceCounter  --> T
 * check empty: overload operator! and operator bool.
 * convertion between pointers to objects in on inheri tree: template member function
 * const/non-const