Now I'm going to ask a question about pointers that is probably very simple, even though an hour of searching on google has yielded nothing.
I'm currently working on my Gamepad class, which contains seven pointers of type PadCommand. PadCommand is an abstract base class, so the pointers are meant to be dynamically allocated to one of the base classes.
I'm currently writing the copy constructor for the Gamepad class:
Gamepad(const Gamepad &g)
name = g.name;
// Set pointers equal down here
The problem is, when I set the pointers equal it does a soft copy of the pointer, so the pointers point to the exact memory address of the pointers from the other Gamepad object. The result is, when the other Gamepad object memory is freed, the pointers in this object become garbage, because they were pointing to those addresses.
So basically, how do I make a copy of a dynamically allocated pointer so that the new pointer is the same object without pointing to the same memory address?
Sorry if my explaination sucks, I've been at this for awhile now and am quite tired. Any help would be appreciated.
Ugh, I should've used smart pointers[lol]