Saving objects in a heterogeneous vector with stacked objects
Hello,
Say I have an abstract CA class derived from CA1, CA2, and possibly others.
I want to put objects of these derived types in a vector that I injected into the CB class. To get polymorphism correctly, I need to save the pointer vector:
class CB
{
std::vector <CA*> v;
};
Now, let's say I have the following main function:
int main()
{
CB b;
CA1 a1;
CA2 a2;
b.Store( a1 );
b.Store( a2 );
}
How to write a method in a void CB::Store(const CA&)simple way, so the saved objects are saved when the original objects are destroyed (which is not found in the simple example above).
, , , ? , RTTI , , ( ) , . , ?
?
( !)