123456
class Foo { int d; public: Foo (int i) : d(i) {} Foo () : Foo(42) {} //new to c++11 };
123456789
class Foo { int d; public: Foo (int i) : d(i) {} Foo () { int a = rand() % 100; this->Foo(a); } };
error: invalid use of ‘Foo::Foo’
Foo () : Foo(rand() % 100) {}
rand() % 100
12345
if(rand() < 10) { x = new Foo(10); } else { x = new Foo(0); }//...
this->Foo(a);
this
12345678
class Foo { int d; public: Foo (int i) : d(i) {} Foo () { d = rand() % 100; } };