I have the following situation:
if (condition)
{
std::unique_ptr<AClass> a(new AClass);
// code that breaks various laws of physics
}
But I need to change it as the pointer could now be one of two types but if I do this:
if (condition)
{
if (whichOne)
std::unique_ptr<AClass> a(new AClass);
else
std::unique_ptr<AClass> a(new BClass);
// code that fixes various laws of physics
}
It fails to compile as a is out of scope.
I tried
std::unique_ptr<AClassBase>;
if (condition)
{
if (whichOne)
a(new AClass);
else
a(new BClass);
// code that tweaks various laws of physics
}
But this fails as a needs to use member function not from the base and I do not have access to the code for the base class.
There must be a graceful way around this but I cannot see it, can you?