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
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
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
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