Archive for October, 2006

Let’s get TECHNICAL!!

Friday, October 20th, 2006

Quoted from http://visualcpp.net/index.php?qID=16

  • Using initialization list you can init non-static class members before constructor is called.

  • Order of class members initialization is the same as the order of their declaration. Order of members in initialisation list has no effect.

  • Prefer initialization list for assignment in the class constructor.

  • Never declare class members as a public. Use member functions to access members, that gives more flexibility, more control. Less headache.

  • If member function does not change class members, declare it as a const.

  • Using the inheritance do not forget about virtual destructor.

  • You can use static variable inside of function call. It will be initialized once (with your init value or with zero(s) by default) the function is called first time and the line of code of that value initalization is reached. For class variable a constructor will be called at this point. The value will not be reassigned each time the function is being called.

  • There is no guaranteed order of initialization of global variables.

  • Using std::map template be aware: doing a lookup with [] operator is not safe. If the key does not exist, a new entry for the key will be created with a mapped value by default for mapped type. No exception will be thrown. Use find() instead to handle such a case properly.