i have two independent class hierarchies, starting at BaseClass1, BaseClass2
this is what I want to do:
struct BaseClass1 {
virtual void obtain_map(std::map<int,BaseClass2> &map) = 0;
}
Subclasses of BaseClass1 override the obtain_map. But the problem is that those sublcasses should be able to use subclasses of BaseClass2 in the map parameter. (So in this sense, subclasses of the two “independent” hierarchies are actually related, or rather can be if the subclass designers want)
How can I accomplish this, or am I forced to create my own map class from scratch?
If you derive your classes like so and use pointer as the second
maptemplate parameter (a smart pointer likestd::unique_ptrwill save you some memory management trouble):You can still pass in
mapswith derived versions of BaseClass2 as the second type: