I'm using an array of pointers to dynamically allocate class instances of a class and it's derived classes. I'm doing great so far, except when I have to copy an object. I'm getting bugs in my program and I think I know why. I just don't know how to solve the problem.
I declare the array of pointers like this:
class CObject {
...
...
}
CObject *templates[MAXOBJS];
CObject *pointers[MAXOBJS];
Here's where the problem lies. I want to copy a *templates object to a *pointers object. If I use:
pointers[50] = templates[50];
This just copies the pointer, and not the data at the pointer's address, correct? So if I were to:
pointers[50].String = "Hello";
Now I have just modified templates[50].String as well? How do I actually copy the data vs. the address?
(Yes I'm aware both source and destination pointers must point to an object created with the new keyword)