Copying object from a superclass pointer
<p>Suppose I have two classes a base class and an inherited class as follows:</p>

<pre><code>class Magic : public Attack
{
public:
    Magic(int uID, std::string &amp;name) : Attack(ActionType::MagicAction, uID, name)
    {

    }
};

class MacroMagic : public Magic
{
    MacroMagic(int uID) : Magic(uID, std::string("Testing"))
    {
    }
    void PreUse() override
    {
        std::cout &lt;&lt; "Test" &lt;&lt; std::endl;
    }
}
</code></pre>

<p>I have a shared_ptr to an instance of magic that I would like to copy, but at runtime I will not know whether that pointer points to an instance of Magic, MacroMagic or anything that may have inherited from Magic. I want to be able to copy the object pointed to by the shared_ptr like so:</p>

<pre><code>Battles::magic_ptr mgPtr = MagicNameMap[name];
            if (mgPtr.get() != nullptr)
            {
                return magic_ptr(new Magic(*mgPtr));
            }
            return mgPtr;
</code></pre>

<p>where magic_ptr is a typedef for a shared_ptr around the Magic Class. I could do it by specifying a virtual copy function and calling that, but I'd like to make it less obtuse and easier to maintain. I assume I can do this by a copy constructor, but I'm unsure how to in this instance. The way I have it now, the pointer returned by the above code will not call the override pReUse() function.</p>

<p>A bit of guidance would be much appreciated, thanks</p>
