Skip to content

Instantly share code, notes, and snippets.

@sy6sy2
Last active July 1, 2020 06:46
Show Gist options
  • Select an option

  • Save sy6sy2/7c74103f164578d57682bd9566fc02b8 to your computer and use it in GitHub Desktop.

Select an option

Save sy6sy2/7c74103f164578d57682bd9566fc02b8 to your computer and use it in GitHub Desktop.
[C++ Style Guide] #CPP

C++ Style Guide

Disclaimer

There is no "official" C++ style guide. This one is my C++ style, that's all.

File extensions

  • Source files: .cpp
  • Header files: .hpp

File names

Snake case with name of the class if any.

Naming

Case styles

  • Camel case: camelCase
  • Pascal case: PascalCase
  • Snake case: snake_case
  • Kebab case: kebab-case

Namespaces

Snake case, with preference to single words.

namespace communication
{
	[...]
}

Enums

Pascal case for the enum name and upper case with underscores for the values.

enum class Dummy
{
  VALUE_X,
  VALUE_Y
};

Classes

Pascal case. Filename has to match the class name.

class Logger
{
    [...]
};

Private variables

Snake case with a m_ prefix to distinguish it from public data

private:
  int m_data;

Member functions

Camel case.

class PrivateSize
{
  public:
    int width() const;
    int getData() const;
};

Other variables

All other names use snake case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment