Original Post
As I have discovered recently, having a vector of polymorphic objects doesn't work. If classes B, C, and D inherit from A they will all behave like an A object in a vector of A's because the part of them that was B, C, or D is chopped off... is there some substitution for this?
I have a class that has as a member a vector of virtual objects. This virtual object has between 20-40 objects that inherent from it. Is there any clean way to do this so that these classes will behave like they are supposed to, instead of like the one virtual class they inherit from? I know now a vector won't work, and I was told I could use a vector of pointers, and have one vector for each type of derived object that those pointers point to, but that would be very messy. Is there any other way?
I have a class that has as a member a vector of virtual objects. This virtual object has between 20-40 objects that inherent from it. Is there any clean way to do this so that these classes will behave like they are supposed to, instead of like the one virtual class they inherit from? I know now a vector won't work, and I was told I could use a vector of pointers, and have one vector for each type of derived object that those pointers point to, but that would be very messy. Is there any other way?