简体   繁体   中英

Mixing boost smart pointers and C++11 smart pointers in boost::signals2

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?

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.

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. Therefore, when you are using boost::signals2 I'd suggest you to stick with boost::weak_ptr .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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