I'm facing the following situation:
class Base{
virtual void Stuff() = 0;
};
class ConcreteA : public Base{
void Stuff() {};
};
class ConcreteB : public Base{
void Stuff() {};
};
class Context {
Base exec() {
ConcreteA conc_a();
return a;
}
};
Of course the compiler gives me an error since Base
is abstract. However, I'd need that exec()
return a Base type. I know that I can make the compiler happy using pointers or references, but since the object ConcreteA is created in exec()
, returning by value is the best way to avoid dangling references or pointer with undefined ownership.
Is there a way to avoid using pointers or references to handle this kind of situations?