c++ - How to declare a reference and initialize later -
i new c++ , here's situation. have reference myojbect
, the exact object depends on condition. want this:
myobject& ref; if([condition]) ref = myobject([something]) else ref = myobject([something else]);
i cannot right because compiler not allow me declare not initialize reference. can accomplish goal here?
you need initliaze it. if conditionally initialize it, can this:
myobject& ref = (condition) ? myobject([something]) : myobject([something else]);
c++ reference
No comments:
Post a Comment