Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joyhuang9473/256d5d2018babb1c1491 to your computer and use it in GitHub Desktop.
Save joyhuang9473/256d5d2018babb1c1491 to your computer and use it in GitHub Desktop.
Constructor initializer lists can be all on one line or with subsequent lines indented four spaces.
// When it all fits on one line:
MyClass::MyClass(int var) : some_var_(var), some_other_var_(var + 1) {}
// When it requires multiple lines, indent 4 spaces, putting the colon on
// the first initializer line:
MyClass::MyClass(int var)
: some_var_(var), // 4 space indent
some_other_var_(var + 1) { // lined up
...
DoSomething();
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment