mercredi 27 juillet 2016

How to deep copy an abstract class array in C++

I have abstract class Figure. Then I have an array of it, and I want to resize it, but not sure how to do it.

Figure ** arr; //lets assume it's filled with some data
Figure ** temp = new Figure * [size + 1];
for(int i =0; i < size; ++i)
{
   temp[i] = new Figure(); //it doesn't let me to create object from the abstract class
   temp[i] = arr[i] //if I do this, once I delete arr, I will lose temp as well
}

Any help?

Aucun commentaire:

Enregistrer un commentaire