What is the difference between the following three pieces of code with respect to MSVC?
Code 1: Foo ctor defined as:
Foo::Foo(Bar &bar = Bar());
Foo ctor used as:
Foo foo = new Foo();
Code 2: Foo ctor defined as:
Foo::Foo()
{
Bar bar = Bar();
Foo(bar);
}
Foo::Foo(Bar &bar);
Foo ctor used as:
Foo foo = new foo();
Code 3: Foo ctor defined as:
Foo::Foo(Bar &bar);
Foo ctor used as:
Bar bar = Bar();
Foo foo = new foo(bar);
Edit: Made corrections to the code. The intention was to explain the idea, didn't focus on the code, so made the mistake. Sorry about that.
The question specifically is to figure out the difference between code 2 and 3. Due to some reason, in the case of Code 2, the consumer of the Foo class ctor results in a crash and in case of Code 3 it doesn't. I don't have the specific code of the consumer, so cannot figure it out myself.