-
Notifications
You must be signed in to change notification settings - Fork 0
CPP Style Guide
Cedric Sirianni edited this page Nov 2, 2023
·
2 revisions
Follow these rules when writing C++:
- All headers should have #define guards
- Use headers over forward declarations at the top of a file
- Never put anything in the std namespace
- Avoid global variables
- Never use
using namespace
- Use header files with namespaces (e.g.
database
) - Document any public functions, classes, methods, or members using Doxygen in the header file
- Don't document private stuff or stuff in an anonymous namespace
- Use const reference whenever possible
- Avoid global variables
- No virtual functions in constructors
- Only use a struct for passive data. Put everything else in a class
- Prefer struct over pair or tuple
- Use return values over output parameters
- Avoid functions over 40 lines
- Use nullptr instead of NULL
- Member variables should have a trailing '_'
- Use auto if it makes the code cleaner
- Variable names are snake_case
- Function names are camelCase
- Class names are PascalCase
Include directives should be in the following order:
- C system headers
- C++ std headers
- Library headers (spdlog, etc.)
- Project headers