samedi 10 août 2019

Polymorphism with array c++ 11

I am confuse. Do you have to do delete s[] at the end of the code?

What is the correct way of assigning derived class objects to an array (fixed size) of type base class ?

int main () {

    Shape *s[2];
    s[0] = new Circle(...);
    s[1] = new Rectangle(...);
    // etc

    delete s[] // Do you have to delete ?
}

-

Aucun commentaire:

Enregistrer un commentaire