C++ and STL
  Common Issues
  Destructor
  regex
  string
 MFC
  CButton
  CDialog
  CEdit
  CInternetSession
  CWinThread
  CWnd
 MS VS FAQ
  Compiling, building
  Debugging
  Editor
  Settings
 Win32, API
  Console
  File System
  Graphics
  Internet functions
  Kernel objects
  Security
  Sound
  Thread, process
  Window
 Windows NT/2K*
  Logon, logoff...
  Networking
  Service Packs
 | About
  About
  Links & Freeware

Powered by
CoderTown



One Line Design Tips

The following are simple but useful tips to be aware while you design your applications:

  • 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.


Created: 2003-05-12
Updated: 2004-12-24

Google
 
Web visualcpp.net
msdn.microsoft.com codeguru.com