multi_index + pure abstract

Doesn't multi_index accept hold classes that has pure abstract methods? Even if these methods aren't used by the container? Is there a way to get the container to hold objects with same interface? -- Animal Frontline Liberation

----- Mensaje original ----- De: fungos <fungos@gmail.com> Fecha: Domingo, Diciembre 10, 2006 5:38 pm Asunto: [Boost-users] multi_index + pure abstract Para: boost-users@lists.boost.org
Doesn't multi_index accept hold classes that has pure abstract methods? Even if these methods aren't used by the container? Is there a way to get the container to hold objects with same interface?
multi_index_container is in this aspect entirely analogous to any other container in C++: you can't store elements of an abstract type because abstract types are, by definition, not instantiable, but you can store pointers (or smart pointers) to an abstract type, for instance: class abstract_base { public: virtual int f()const=0; ... }; typedef multi_index_container< boost::shared_ptr<abstract_base>, indexed_by< ...
container_type;
As a bonus extra, you can use member functions of abstract_base (even pure virtual ones) as your key extractors without having to care about the extra level of dereference imposed by shared_ptr<>, for instance: typedef multi_index_container< boost::shared_ptr<abstract_base>, indexed_by< ordered_unique< const_mem_fun<abstract_base,int,&abstract_base::f> >, ...
container_type;
This "automatic dereferencing" capability of B.MI predefined key extractors is explained at http://tinyurl.com/mpjae . Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
"JOAQUIN LOPEZ MU?Z"
-
fungos