I have different types of, say A, B, Cthat all derive from a base class Base:
class Base { ... };
class A : public Base { ... };
class B : public Base { ... };
class C : public Base { ... };
I need a container, call it Master, which contains pointers to type objects A, Band C. I want the container to Masterprovide an iterator over all contained objects Base, as well as specifically typed iterators on top of all contained objects A, Band C. I use as storage std::vector, but it would be nice if it were easy to switch later.
Conceptually, this is an interface that Mastershould be presented in the outside world:
class Master {
public:
add(A *a);
add(B *b);
add(C *c);
remove(Base *base);
iterator<A*> a_begin();
iterator<A*> a_end();
iterator<B*> b_begin();
iterator<B*> b_end();
iterator<C*> c_begin();
iterator<C*> c_end();
iterator<Base*> base_begin();
iterator<Base*> base_end();
};
. , someMaster.begin<A>() .
, , . . , Master , D, E F ( Base). , .
dynamic_cast ing, . , . ?