Hi,
I have a class which has a private attribute which is a reference to another class:
class A {
public:
A();
A(B& anotherB);
private:
B& bRef;
}
In my A(B& anotherB), I can do this:
A::A(B& anotherB)
: bRef(anotherB) {
}
But what about A()? I tried this:
A::A()
: bRef(B()) {}
But I get this error 'error: invalid initialization of non-const reference of type ‘B&’ from a temporary of type ‘B’.
How can I call initialize B reference in A with the default constructor of B?
Thank you.