I need to make a duplicate of an instance of a class which is held on an STL vector and put it onto another STL vector. The class inherits from a base class which is used when declaring the vectors:
Maneuver is the base class of which several variants are derived from, and then added to these two lists like such:
maneuvers.push_back( new AIManeuverFlank );
To copy one of the instances on maneuvers vector to the requestedmaneuvers vector, I do this:
BYTE * temp = new BYTE[ maneuvers[ i ]->GetSize() ];
memcpy( temp, maneuvers[ i ], maneuvers[ i ]->GetSize() );
requestedmaneuvers.push_back( (Maneuver*) temp );
GetSize() gives the size of the derived class, because sizeof( *maneuvers[ i ] ) seems to return the size of the base class only.
Thus far this works ok but seems sloppy. My question is whether this is acceptable practice, or is there a simpler method to perform this copy? I don’t need to worry about any dynamic containers that might be members either the base or derived classes.
Thanks for reading,