It\'s been a while since I have had to write C++ code and I\'m feeling kind of stupid. I\'ve written code that is similar to, but is not exactly, the code b
A Parent
object returned by value cannot possibly contain any Child
information. You have to work with pointers, preferably smart pointers, so you don't have to clean up after yourself:
#include
class Factory
{
// ...
public:
static std::unique_ptr GetThing()
{
return std::make_unique();
}
};
int main()
{
std::unique_ptr p = Factory::GetThing();
if (Child* c = dynamic_cast(p.get()))
{
// do Child specific stuff
}
}