vimwiki

C++ convention

Based on this

Following Google C++ sytle guide

Recap

element naming convention example
class PascalCase ClassName
function PacalCase BubbleSort()
variable snake_case my_variable

Naming convention

Name never start with digit.

Can’t use a predefined keyword.

User defined class and function use PacalCase

LinkedList or BubbleSort()

Variable uses snake_case

student_id or result

Punctuation marks

Example:

int GetLargerNumber(int num_one, int num_two) {
    if (num_one > num_two) {
        return num_one;
    }
    else {
        return num_two;
    }
}

Formatting

Spacing

string message = "hello world";
#include <iostream>    // preprocessor directive
 
float pi = 3.1415;    // global variable
 
class MyClass {        // class
  public:
    myClass() {
  }
};
 
int main() {        // function
  return 0;
}

Indentation

Each new block (loop, method…) opening should be intended.

Level of indentation: ?? (2 or 4)

Line length