I have an application which uses boost::signals2
to communicate between components. I am trying to use it's automatic connection management features through slot_type(...).track(weak_ptr)
.
The problem:
Throughout my program, std::shared_ptr
is used. .track
expects a boost::weak_ptr
, and I am providing an std::weak_ptr
.
Here's the exact error I'm getting:
cannot convert argument 1 from 'std::weak_ptr<_Ty>' to 'const boost::weak_ptr<void> &'
Is there a workaround for this? Or have I misunderstood the problem?
C++11 introduced smart pointers as part of the standard library, inside the <memory> header file. Smart pointers reduce some of the manual programming work associated with memory management. They provide automated ways of detecting when to delete pointers, and try to protect developers from introducing memory leaks.
These smart pointer class templates have a template parameter, T, which specifies the type of the object pointed to by the smart pointer. The behavior of the smart pointer templates is undefined if the destructor or operator delete for objects of type T throw exceptions. T may be an incomplete type at the point of smart pointer declaration.
However, while boost::shared_ptr keeps track of the number of shared pointers referencing a particular object, the developer has to do this when using boost::intrusive_ptr. This can make sense if other classes already keep track of references. boost::intrusive_ptr is defined in boost/intrusive_ptr.hpp.
When a Boost.Intrusivehook is configured with a smart pointer as an argument, this pointer configuration is passed to the containers. For example, if the following hook is configured with a smart pointer (for example, an offset pointer from Boost.Interprocess):
I found a solution, and it was to use .track_foreign
instead of .track
. It allows the use of C++11 smart pointers in place of the boost smart pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With