C++ Version
Currently, code should target C++17
Header file
Use header file.
i.e. Every .cc file should have an associated .h file.
Exceptions: such as unit tests and small .cc files containing just a mian() function.
Use of header files is much better for the readibility, size and performance of the code.
(1) Self-contained Headers
Header file should be self-contained and end in .h.
Non-header file should end in .inc.
Place the definitions for templated and inline funtions in the same file as their declarations. The definitions of these constructs must be included into every .cc file that use them, or the program may fail to link in some build configurations.
(2) The #define Guard
All header files should have #define guards to prevent multiple inclusion.
To guarantee uniqueness, they should be based on the full path in a project's source tree.
For example, the file foo/src/bar/baz.h in project foo should have the following guard :
// format : <PROJECT>_<PATH>_<FILE>_H_
#ifndef FOO_BAR_BAZ_H_
#define FOO_BAR_BAZ_H_
...
#endif // FOO_BAR_BAZ_H_
(3) Include what you use
영어 공부 목적으로 영어로 요약을 해보려고 했는데 결국에는 다 받아적게 된다....
즉 공식 가이드에서 버릴 것이 없다...
다 읽어보는걸 추천한다...
Visual studio 서식 스타일과 Google C++ 스타일 비교
Visual Studio 서식 스타일 | Google C++ Style |
#include <iostream> int mian() { std::cout << "Hello World" << std::endl; return 0; } |
#include <iostream> int main() { std::cout << "Hello World" << std::endl; return 0; } |
탭 띄어쓰기 중괄호 위치 - 다음 라인 |
스페이스 띄워쓰기 중괄호 위치 - 문장 끝에 시작 괄호 |
중괄호 위치를 지키지 않을 경우 cpplint에서 아래와 같은 warning이 나온다 { should almost always be at the end of the previous line [whitespace/braces] |