Consider the following code:
class Foo {
Foo() {}
};
class Bar {
Foo &Foo_ref;
Bar() : Foo_ref() {}
};
Complied as is, I get the error:
tmp.cc: In constructor Bar::Bar(): tmp.cc:7: error: value-initialization of Foo& Bar::Foo_ref, which has reference type
I’ve tried every variation I can think of. What am I doing wrong? How do I initialize a reference member to a new instance?
I’m using a const pointer instead of a reference as a workaround for now, but I’d prefer to use a reference.
What’s wrong with
if you want a brand-new Foo object?