In the following constructor, the string with Foo() does not delegate to the previous constructor. Instead, it creates a new temporary object of type Foo that is not associated with *this .
Foo(int b) { bar = 0; Foo(); // NOTE: new temporary instead of delegation bar += b; cout << "Foo(int) called" << endl; }
The division of the constructor works as follows:
Foo(int b) : Foo() { bar += b; cout << "Foo(int) called" << endl; }
However, this is only possible with C ++ 11.
nosid
source share