I'm making a copy-constructor in a class called Registry, which handles an array of pointers of the abstract class Competitor, while Amateur and Professional inherit from Competitor.
How would I go about transferring these to the array of the new Registry-object from the Registry-object I passed in to copy from?
Usually when I'm dealing with a concrete class I would make a for-loop and then do something like:
for(int i=0; i<this->size; i++)
this->arrOfComp[i] = new Competitor(*original.arrOfComp[i]);
Where original is a parameter of type Competitor.
But I can't allocate Competitor obviously now that it is abstract. And I don't know what type the next object in the array is, so I can't just change it to ... new Amateur(...) or ... new Professional(...), they're not all the same, it's mixed; some are Amateurs, some are Professionals.
Is there some elegant way of making it transfer every object regardless of class so I don't have to write two if-statements and use typeid, dereferencing etc.?
And I know vectors might be the first thing that may come to your mind, but this is an assignment and I don't have a choice.
I checked this one: Copy constructor for abstract class
But it was about Java, I don't know how to make that for C++.