I have a reference to some class MyObject
, but the exact object depends on a condition. I want to do something like this:
MyObject& ref;
if([condition])
ref = MyObject([something]);
else
ref = MyObject([something else]);
I cannot do this right now because the compiler does not allow me to declare but not initialize a reference. What can I do to achieve my goal here?
See Question&Answers more detail:os