I have a reference to MyOjbect, but the the exact object depends on a condition. So I want to do something like this:
MyObject& ref;
if([co
I usually do this (C++ 11 or later):
std::shared_ptr pObj;
if(condition)
pObj = std::make_shared(args_to_constructor_1);
else
pObj = std::make_shared(args_to_constructor_2);
which is clean and allows using object definition with (possibly different) constructions, a thing you can't do directly with pointers as the compiler will complain from using temporary objects.