55 Specific procedure notes for changing procedures and designs

Source: Internet
Author: User

1. Make yourself accustomed to C + +

    1. Depending on C + + as a language federation
      1. The C + + efficient programming code varies depending on your use of the C + + part
    2. Replace # define with const, enum,inline as much as possible
      1. For simple light, it is best to replace #defines with a const object or emuns
      2. For macros that resemble functions (macors), it is best to use the inline function instead of #defines
    3. Use the const as much as possible
      1. Declaring something as const can help the compiler detect the wrong usage. Const can be applied to objects in any scope, function arguments, function return types, member function ontologies
      2. The editor enforces bitwise constness, but you should use "Conceptual constants" (conceptual constness) when you write programs
      3. When the const and NON-CONST member functions have a substantially equivalent implementation, making the NON-CONST version call the const version avoids code duplication
    4. Determines that an object has been initialized before it is used
      1. Manual initialization of built-in objects because C + + does not guarantee that they are initialized
      2. Constructors are best used with member initial columns (member initialization list), rather than using assignment operations (assigment) within the constructor's body, the member variables of the initial column list should be in the same order as they were declared in class
      3. To avoid the "initialization Order of cross-compilation units" issue, replace the non-local static object with a local static object

2. Construction/destructor/assignment operation

    1. Understand C + + silently writing and calling those functions
      1. The compiler can secretly create default constructors, copy constructors, copy assignment operators, and destructors for class
    2. If you want to use an automatically generated function from the editor, you should explicitly reject
      1. To dismiss the compiler's ability to automatically (secretly) provide, the corresponding member function can be declared private and not implemented. Using a base class like uncopyable is also a practice
    3. Declaring a virtual destructor for a polymorphic base class
      1. Polymorphic (with polymorphic) base classes should declare a virtual destructor. If class takes any virtual function, he should have a virtual destructor
      2. The purpose of class is not to declare a virtual destructor if it is not used as base classes, or for polymorphism (polymorphically)

55 Specific procedure notes for changing procedures and designs

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.