Google C + + Style Guide Read NOTE 1

Source: Internet
Author: User
Background

C + + is the main language used by Google's open source projects, although Google Code is yellow. C + + is a powerful language that adds to its complexity. In order to let the code by other programmers understand, reduce the possibility of a bug, so with this Google C + + style guidance.

Header Files
  • Each. cc file should be associated with an. h file, unless it is a unit test or contains only one main ();
The #define Guard
  • Each header file should be avoided for repeated inclusion. The macro definition can be in project_path_file_h_ format.
    For example:
    #ifndef Foo_bar_baz_h_
    #define Foo_bar_baz_h_
    ...
    #endif//Foo_bar_baz_h_
  • Do not use # include in cases where the predecessor declaration is sufficient. A change to the header file will cause the file containing it to be recompiled, so it is recommended that the minimum inclusion principle, especially the header file containing the other header files, be included.
    For example, when you need to use the file class but do not need to use the definition declaration of the class, you can use the predecessor declaration class file in the header file instead of the #include "file/base/file.h"
    How to use the Foo class when the header file does not get the Foo definition?
    • Declare data members using Foo * or Foo &.
    • You can define and return values in a function declaration.
    • With static data members, static members are defined outside the class.
      But if your class is a subclass of Foo or has a data member of type Foo, it contains the header file. Do not overdo the loss of header file inclusions, resulting in increased code complexity and performance consumption.

Google C + + Style Guide Read NOTE 1

Related Article

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.