TIPS FOR C++
2007-03-27 16:56
351 查看
[!]Represent concepts as classes;
[2]Use public data(structs) only when it really is just data and no invariant is meaningful for the data members;
[3]A concrete type is the simplest kind of class.When applicable,prefer a concrete type over more complicated class and over plain data structure;
[4]Make a function a member only if it needs direct access to the representation of a class;
[5]Use a namespace to make the association between a class and its helper functions explicit;
[6]Make a member function that does't modify the value of its object a const member function;
[7]Make a function that needs access to the representation of a class but needn't be called for a specific object a static member function;
[8]Use a constructor to establish an invariant for a class;
[9]If a constructor acquires a resource,its class needs a destructor to release the source;
[10]If a class has a pointer member,it needs copy operations(copy constructor and copy assignment);
[11]If a class has a reference member,it probably needs copy operations(copy constructor and copy assignment);
[12]If a class needs a copy operation or a destructor,it probably needs a constructor,a destructor,a copy assignment,and a copy constructor;
[13]Check for self-assignment in copy assignments;
[14]When writing a copy constructor,be careful to copy every element that needs to be copied
(beware of default initializers);
[15]When adding a new member to a class,always check to see if there are user-defined constructors that need to be updated to initialize the member;
[16]Use enumerators when you need to define integer constants in class declarations;
[17]Avoid order dependencies when constructing global and namespace objects;
[18]Use first-time switches to minimize order dependencies;
[19]Remember that temporary objects are destroyed at the end of the full expression in which they are created;
[2]Use public data(structs) only when it really is just data and no invariant is meaningful for the data members;
[3]A concrete type is the simplest kind of class.When applicable,prefer a concrete type over more complicated class and over plain data structure;
[4]Make a function a member only if it needs direct access to the representation of a class;
[5]Use a namespace to make the association between a class and its helper functions explicit;
[6]Make a member function that does't modify the value of its object a const member function;
[7]Make a function that needs access to the representation of a class but needn't be called for a specific object a static member function;
[8]Use a constructor to establish an invariant for a class;
[9]If a constructor acquires a resource,its class needs a destructor to release the source;
[10]If a class has a pointer member,it needs copy operations(copy constructor and copy assignment);
[11]If a class has a reference member,it probably needs copy operations(copy constructor and copy assignment);
[12]If a class needs a copy operation or a destructor,it probably needs a constructor,a destructor,a copy assignment,and a copy constructor;
[13]Check for self-assignment in copy assignments;
[14]When writing a copy constructor,be careful to copy every element that needs to be copied
(beware of default initializers);
[15]When adding a new member to a class,always check to see if there are user-defined constructors that need to be updated to initialize the member;
[16]Use enumerators when you need to define integer constants in class declarations;
[17]Avoid order dependencies when constructing global and namespace objects;
[18]Use first-time switches to minimize order dependencies;
[19]Remember that temporary objects are destroyed at the end of the full expression in which they are created;
相关文章推荐
- (转)Tips for Optimizing C/C++ Code
- Compiling, Linking and Debugging Tips for C++
- TIPS FOR C++
- TIPS FOR C++
- Debugging Tips and Tricks for C++ in Visual Studio
- 《Tips for Optimizing C/C++ Code》译文
- Three Optimization Tips for C++
- C++优化三板斧:Three Optimization Tips for C++
- 《Tips for Optimizing C/C++ Code》译文
- Tips for Optimizing C/C++ Code
- [C/C++] - Tips for Better Coding Style
- [Memo] Tips and Tricks for using C++ I/O.
- [C/C++] - Tips for STL and Generic Programming
- 《Tips for Optimizing C/C++ Code》译文
- GDB Tutorial: Advanced Debugging Tips For C/C++ Programmers
- TIPS FOR C++3
- Dijkstra's Shortest Path - C++ for C Programmers 2.5
- Some tips for using CCS
- 用 IAR C/C++ For ARM 编写嵌入式应用的启动细节[转]
- C++ IDE for Linux