|
Boost Users : |
Subject: [Boost-users] [Interprocess] Collection of base shared_ptr
From: Aaron_Wright_at_[hidden]
Date: 2012-04-03 15:18:22
I'm using Boost 1.49, and Visual Studio 10.
I'm having a hard time figuring out how to store a shared_ptr to a derived
class in a collection of shared_ptr to the base class. This is something I
do all the time with normal shared pointers. This is my code:
{
struct Base {};
struct Derived : public Base {};
typedef
boost::interprocess::managed_shared_ptr
<
Base,
boost::interprocess::managed_shared_memory
>::type Base_ptr;
typedef
boost::interprocess::deque
<
Base_ptr,
boost::interprocess::managed_shared_memory::allocator< Base_ptr
>::type
> Queue;
struct shm_remove
{
shm_remove() {
boost::interprocess::shared_memory_object::remove("testing"); }
~shm_remove() {
boost::interprocess::shared_memory_object::remove("testing"); }
} remover;
boost::interprocess::managed_shared_memory shared_memory(
boost::interprocess::create_only,
"testing",
65536);
Queue* queue =
shared_memory.construct< Queue
>(boost::interprocess::anonymous_instance)(
shared_memory.get_allocator< Base_ptr >());
queue->push_back(
bi::make_managed_shared_ptr< Derived >(
shared_memory.construct< Derived >(bi::anonymous_instance)(),
shared_memory));
}
The compiler tells me a bunch of cryptic stuff, I think it has to do with
the different deleter types:
boost/container/deque.hpp(1040): error C2664:
'boost::interprocess::shared_ptr<T,VoidAllocator,Deleter>::shared_ptr(const
boost::interprocess::offset_ptr<PointedType,DifferenceType,OffsetType,OffsetAlignment>
&,const VoidAllocator &,const Deleter &)' : cannot convert parameter 1
from 'const boost::interprocess::shared_ptr<T,VoidAllocator,Deleter>' to
'const
boost::interprocess::offset_ptr<PointedType,DifferenceType,OffsetType,OffsetAlignment>
&'
5> with
5> [
5> T=Base,
5>
VoidAllocator=boost::interprocess::allocator<void,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5>
Deleter=boost::interprocess::deleter<Base,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5> PointedType=Base,
5> DifferenceType=ptrdiff_t,
5> OffsetType=size_t,
5> OffsetAlignment=0
5> ]
5> and
5> [
5> T=Derived,
5>
VoidAllocator=boost::interprocess::allocator<void,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5>
Deleter=boost::interprocess::deleter<Derived,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>
5> ]
5> and
5> [
5> PointedType=Base,
5> DifferenceType=ptrdiff_t,
5> OffsetType=size_t,
5> OffsetAlignment=0
5> ]
5> Reason: cannot convert from 'const
boost::interprocess::shared_ptr<T,VoidAllocator,Deleter>' to 'const
boost::interprocess::offset_ptr<PointedType,DifferenceType,OffsetType,OffsetAlignment>'
5> with
5> [
5> T=Derived,
5>
VoidAllocator=boost::interprocess::allocator<void,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5>
Deleter=boost::interprocess::deleter<Derived,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>
5> ]
5> and
5> [
5> PointedType=Base,
5> DifferenceType=ptrdiff_t,
5> OffsetType=size_t,
5> OffsetAlignment=0
5> ]
5> No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
5> test.cpp(94) : see reference to function template
instantiation 'void
boost::container::deque<T,A>::push_back<boost::interprocess::shared_ptr<Derived,VoidAllocator,Deleter>>(const
BOOST_MOVE_TEMPL_PARAM &)' being compiled
5> with
5> [
5> T=Base_ptr,
5>
A=boost::interprocess::allocator<Base_ptr,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5>
VoidAllocator=boost::interprocess::allocator<void,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5>
Deleter=boost::interprocess::deleter<Derived,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,
5>
BOOST_MOVE_TEMPL_PARAM=boost::interprocess::shared_ptr<Derived,boost::interprocess::allocator<void,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>,boost::interprocess::deleter<Derived,boost::interprocess::segment_manager<char,boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interprocess::iset_index>>>
5> ]
--- Aaron Wright
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net