vendredi 23 juin 2017

Set of Base class together with inherited classes

In this code snippet below, there is a class of Pets, with inherited classes Cat and Dog. I'd like to have a set of all of my pets.

    class Pet{
    //
};

class Dog: Pet{
    //
};
class Cat: Pet{
    //
};

int main(
        set<Pet> a;

        set<Pet*> b;
)

Obviously if I use option b, any of the pointers, dog or cat, can be in the set, but I'm not sure how I could make a copy of the set.

Similarly, if I make a copy of set a, would the copy constructors of Cat,Dog be called for items of their respective types?

Aucun commentaire:

Enregistrer un commentaire