Effictivec++ 's 50 recommendations __c++

Source: Internet
Author: User

Warning: The parentheses behind the clause are all my own to see the mark, read time to. Just drop it.


1, try to use the const and inline without using #define

2, try to use <iostream> instead of using <stdio.h>

3. Use new and delete as much as possible without using malloc and free


4, try to use C + + style annotation

5, the corresponding new and delete to take the same form

6. Call Delete to pointer member in destructor

7. Pre-prepared memory is not enough

8, write operator new and operator delete time to follow the general

9, avoid hiding the standard type of new

10, if write operator new will write operator delete

11. Declare a copy constructor and an assignment operator for classes that need to dynamically allocate memory

12, try to use initialization instead of assigning values in constructors.

13. The order in which members are listed in the initialization list is the same as the order in which they are declared in the class

14. To determine the virtual destructor function in the base class

15, let operator= return the *this reference.

16. Assign values to all members in operator=

17, in the operator= to check their assigned value of the situation


18, strive to make the excuse of the class complete and small

19. Distinguish member function, non member function and friend function.

20. Avoid public excuse for appearing data member

21, use the const as much as possible.

22, as far as possible using the reference to not use the transfer value

23. Do not attempt to return a reference when an object must be returned.

24. Carefully select between function overload and default value of Set parameter

25. Avoid overloading the pointer and numeric types

26, beware of potential ambiguity

27, if you do not want to implicitly generate a function to be shown to prohibit it.

28, divide the global name space.


29, to avoid the return of the internal data handle.

30. Avoid such member functions: The return value is a non-const pointer or reference to a member, but the member has a lower access level than this function.

31. Never return a reference to a local object, nor return a reference to a pointer that is initialized with new in the function.

32, as far as possible to postpone the definition of variables.

33, the wise use of inline

34. Reduce the variation dependence of the document to the minimum


35, so that the embodiment of a common inheritance is a meaning

36. Differentiate between interface inheritance and implementation inheritance

37, never redefine inherited non-virtual functions

38, never redefine inherited default parameter values

39, to avoid the downward shift to the inheritance level

40, through layering to reflect "have a" or "with a". To achieve "

41. Differentiate Inheritance and templates

42. Using private inheritance Wisely

43, the wise use of multiple inheritance.

44, say what you want to say, understand what you are saying.


45, understand the C + + behind the scenes for you to write, the function called

46, rather than compile and link when there are errors do not run error

47. Ensure that nonlocal static objects are initialized before use

48, pay attention to compiler warning

49, familiar with the standard library.

50, improve the understanding of C + +.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.