4

As I understand the following is valid for boost::shared_ptr:

boost::shared_ptr<SomeData> ptr;
...
boost::shared_ptr<const SomeData> c_ptr = ptr; // Valid

The same behavior does not hold for boost::interprocess::managed_shared_ptr. Why?

TemplateRex
  • 69,038
  • 19
  • 164
  • 304
topoden
  • 111
  • 1
  • 5

1 Answers1

1

boost::interprocess::managed_shared_ptr isn't actually a shared pointer; it's just a helper class that you can use to define the type of one. From the interprocess docs:

typedef managed_shared_ptr<MyType, managed_shared_memory>::type my_shared_ptr;

And the creation of a shared pointer can be simplified to this:

[c++]

my_shared_ptr sh_ptr = make_managed_shared_ptr (segment.construct<MyType>("object to share")(), segment);

With "sh_ptr" from the above example, the following should work:

typedef managed_shared_ptr<const MyType, managed_shared_memory>::type my_shared_const_ptr;
my_shared_const_ptr sh_c_ptr = sh_ptr;

As these two objects are actually shared pointers.

On the other hand, doing:

managed_shared_ptr<MyType, managed_shared_memory> ptr;
managed_shared_ptr<const MyType, managed_shared_memory> c_ptr = ptr;

won't work because in this case ptr and c_ptr are very simple structs that do nothing except make 3 typedefs, so they don't convert.

Corey
  • 1,845
  • 1
  • 12
  • 23