class Bar
{
public:
Bar(): value(21) {}
Bar(int i): value(i) {}
privateint value;
};
class Foo
{
public:
Foo(Bar b)
{
cout << "constructor called" << endl;
}
};
// for this the message "constructor called" is printed on the screen
Foo f(Bar(13));
// but not for these
Foo f(Bar());
Foo f(Bar);
I think the compiler sees the last two
as function declarations or something
So how can I create a Foo object with the Bar default constructor ?
I know this works: