If I have a function that takes possession of one of the arguments, are there any call policies that I should use when I expose that function with Boost.Python?
void func(MyClass* obj)
{
// Code that takes possession of `obj`
}
I think you can use boost::weak_ptr
.
using boost::shared_ptr;
using boost::weak_ptr;
func (weak_ptr<MyClass> wp)
{
shared_ptr<MyClass> sp = wp.lock ();
if (sp)
// sp stays alive until it goes out of scope or is reset
}
Basically, this is the example offered in the documentation of boost::weak_ptr
. Here's the reference .
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.