Returning new base class when the parent class shared pointer is the return type
- by Ben Dol
Can you have a parent class shared pointer return type of a function and then return a new child class without it being a shared pointer? I'm not sure how shared pointers work in these situations, do they act like a regular pointer? Here is my example:
BaseEventPtr Actions::getEvent(const std::string& nodeName)
{
if(asLowerCaseString(nodeName) == "action")
return new ActionEvent(&m_interface);
return nullptr;
}
ActionEvent is the subclass of BaseEvent in this situation.
Cheers!