I have a problem with a school assignment. I am supposed to create a system that keeps track of contenders in a sporting event. I have a base class contender and two classes that derive from that called Professional
and Exerciser
.
And then I have a register class that contains a Contender **contenders
. And I have to create a copy-constructor for this class but I don't know how to do it.
I thought about something like this
Register::Register(const Register& original)
{
this->kap = original.kap;
this->currentAmount = original.currentAmount;
for (int i = 0; i < this->currentAmount; i++)
{
if (Professional* pro = dynamic_cast<Professional*>(this->contenders[i]))
{
this->contenders[i] = new Professional(*original.contenders[i]);
}
if (Exerciser* pro = dynamic_cast<Exerciser*>(this->contenders[i]))
{
this->contenders[i] = new Exerciser(*original.contenders[i]);
}
}
this->initiate(this->currentAmount);
}