Imagine I have a Base class, and two classes that derive from it, One and Two. In Java, I could have the following scenario:
Base b;
if(condition)
b = new One();
else
b = new Two();
where the object type is determined at runtime (the above objects go on the heap).
In C++, I want to be able to instantiate the object type at runtime as well - where all I know is that they both share the same Base type - but I want to keep it stack allocated, like so:
Base b;
What's the best way to do this?