C++ Tidbits
-
You cant have const arrays.
-
Don’t use singleton if it accepts args.
-
Don’t use “using namespace” in header file.
-
Map has a pair array initializer.
-
Don’t use magic numbers.
-
Const int and string values can be defined in header file but not float values.
-
Virtual inheritance is runtime costly, but use it to avoid the diamond inheritance
-
Const instead of #define
-
Use forward declaration in header files.
-
Use Null Object pattern to avoid checking for null
-
A Class should do only one thing.
-
Use const always if possible
-
Use callbacks to initialize/modify/access STL containers.
-
When template is defined in cpp, to avoid linker errors, add template void foo
() to cpp file -
To choose a STL container, follow this cheat sheet. http://linuxsoftware.co.nz/cppcontainers.html
-
Global functions in namespace. Have namespace {} in .cpp file as well
In GCC, erase doesn’t accept const_iterator
Never ever use using namespace in header files. Because sometimes there are certain functions in boost and stl that can get conflicted. Like transform()