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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…