I have a vector of pointers to derived objects inserted by the user (so I assume that the correct term is "known only at runtime):
vector<Person *> vect;
Derived classes are men and women. I want to iterate on a vector to select only the Woman objects and call the copyconstructor instance. I thought 3 solutions:
- Use flag;
- To use typeid
- To insert a call into the copy constructor in the default constructor of Female, so each time the user creates it, automatically create a double.
I do not like the first option for many types of derived classes. I do not like the third option, because it will cause a relationship problem (The world knows that every woman, but a woman cannot know the world). So I have to use the second option: Example
typeid(vect.at(i))==typeid(Female)
Is this expression correct? Is there any other way to outline the problem?
source share