Initializer list

Back

Initializing variables can be done with Initializer list in the contructors

class Test {
  int n;
  char c;
  public:
    Test() : n(1), c{'o'} {}
    Test(n) : n(n) {}
    Test(Test& a) : n(a.n) {}
}

Reference