[英]Mixing boost smart pointers and C++11 smart pointers in boost::signals2
I have an application which uses boost::signals2
to communicate between components. 我有一个应用程序,它使用
boost::signals2
在组件之间进行通信。 I am trying to use it's automatic connection management features through slot_type(...).track(weak_ptr)
. 我试图通过
slot_type(...).track(weak_ptr)
来使用它的自动连接管理功能。
The problem: 问题:
Throughout my program, std::shared_ptr
is used. 在我的程序中,使用了
std::shared_ptr
。 .track
expects a boost::weak_ptr
, and I am providing an std::weak_ptr
. .track
期望一个boost::weak_ptr
,我提供了一个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?
或者我误解了这个问题?
I found a solution, and it was to use .track_foreign
instead of .track
. 我找到了一个解决方案,它使用的是
.track_foreign
而不是.track
。 It allows the use of C++11 smart pointers in place of the boost smart pointers. 它允许使用C ++ 11智能指针代替boost智能指针。
To the eyes of C++, and the compiler, std::weak_ptr
and boost::weak_ptr
are two completely different classes that has nothing in common. 对于C ++而言,编译器,
std::weak_ptr
和boost::weak_ptr
是两个完全不同的类,没有任何共同之处。 Therefore, when you are using boost::signals2
I'd suggest you to stick with boost::weak_ptr
. 因此,当你使用
boost::signals2
我建议你坚持使用boost::weak_ptr
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.