0

I have a game with few different object classes which are all derived from a base class name Gameobject like so:

class Gameobject{...}
class Block : public Gameobject{...}
class Wall  : public Gameobject{...}
class Raw   : public Gameobject{...}

Inside the logic of the game I'm managing some part with actual Blocks and Walls but as Gameobject like:

Gameobject* wall = new Wall();
Gameobject* block = new Block();

And the problem is that I would like to be able to call a copy constructor to copy an object but in the in a way that if I call

Gameobject* newObj = new Gameobject(ObjToCopy);

it will recognize if the object to copy is a wall/block/somethingelse and copy the data in the wall/block/somethingelse class and create an actual wall/block/somethingelse object.

If that helps I have a variable inside the Gameobject class that tells me what class that object is exactly like:

if (genericObject.category=="block"){
    /* cast is like a block and use it like that */
}else{
    /* do other checks */
}
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
elkiwy
  • 59
  • 5

0 Answers0