简体   繁体   English

在boost :: signals2中混合使用boost智能指针和C ++ 11智能指针

[英]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_ptrboost::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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM