Copying Pointers does not do the job.
When shooting bullets, entities must be able to copy a bullet entity. That bullet entity is stored as a pointer in that entity, which has the ability to shoot. Okay, then let’s create a copy-constructor and create a new instance as a copy of that.
So what’s the problem? The entity has a pointer pointing at a graphics node. Okay, then let’s create a copy-constructor for that as well. But we don’t know the specific type of this node (Node has a lot of children: SpriteNode, TextNode etc.), and therefore don’t know which copy-constructor to call.
I found a solution:
Node* Node::copy() { return new Node(*this); }
I got this as a virtual method for every class derived from Node, so they call their own copy-constructors and give back a pointer to the result.
This post was imported from tumblr