Boost logo

Boost :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2006-02-20 09:06:14


tal boost ha escrito:

> Hello,
>
> I having difficulties getting multi_index working with shared_ptr
>
> Example code:
>
> typedef multi_index_container<
>
> NodePtr,
>
> indexed_by<
>
> ordered_unique<
>
> BOOST_MULTI_INDEX_CONST_MEM_FUN(NodePtr, handle,
> getHandle)
>
> >
>
> >
>
> > node_set;
>
> NodePtr is a typedef to boost::shared_ptr<NodeBase>
>
> NodeBase is an interface for other NodeTypes objects the use it.
>
> NodeBase ::getHandle() : handle (handle==size_t)
>
> Using MSVC++ 6.0 compilers complains that getHandle is not a member of
> NodePtr
>
> If I replace NodePtr with NodeBase class it compiles, with a price of giving
> away shared_ptr abilty.
>
> Does anyone have any idea how to get both libs work?
>

OK. You should define your NodePtr_set as follows

   typedef multi_index_container<
     NodePtr,
     indexed_by<
       ordered_unique<
         BOOST_MULTI_INDEX_CONST_MEM_FUN(NodeBase,handle,getHandle)
>
>
> NodePtr_set;

Note that elements are NodePtrs, but the index is based on NodeBase.

This is explained at

http://boost.org/libs/multi_index/doc/advanced_topics.html#advanced_key_extractors

It is possible that you missed that part.

> Regards
> Tal Agmon

Best regards,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk