TheWorstError TheWorstError - 13 days ago 5
C++ Question

What is the difference between these two initializations?

Is there a difference between how these are initialized ? Is one more favorable than the other ?

class Foo{
public:
Foo();
private:
int x_;
};

Foo::Foo() {
this->x_ = 5;
}

Foo::Foo()
: x_(5)
{}

Answer

This is member initialisation and is generally preferable.

Foo::Foo()
  : x_(5)
{}

More in-depth answers are here: Why should I prefer to use member initialization list?