为了帮助自己区分之前学习C语言:
[1]在C++里几乎不需要用宏。consat或enum定义明显的常量,用inline避免函数调用的额外开销,用template去刻画 families of functions of types, and namespace to avoid name clashes.
[2]不要在你需要变量之前去声明它,以保证你能立即对它进行初始化。A declaration can occur anywhere a statement can
,in for-statement initializers,and in conditions.
[3]Don't use malloc(). The new operator does the same job better , and instead of realloc() , try a vector().
[4]Try to avoid void* , pointer arithmetic , unions, and casts,except deep within the implementation of some function or class. In most cases, a cast is an indication of a design error . If you must use an explicit type coversation , try using one of the "new cast" for a more precise statement of what you are trying to do.
[5]Minimize the use of arrays and C-style strings. The C++ standard library string and vector classes can often be used to simplify programming compared to traditional C style.In general ,try not to build yourself what has already been provided by the standard library.
Most important ,try thinking of a program as a set of interacting concepts represented as classes and objects, instead of as a bunch of data structures with functions twiddling their bits.