加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Boost.Python:占有争论

发布时间:2020-12-16 06:57:04 所属栏目:百科 来源:网络整理
导读:如果我有一个占有其中一个参数的函数,那么当我用Boost. Python公开该函数时,是否应该使用任何调用策略? void func(MyClass* obj){ // Code that takes possession of `obj`} 解决方法 我想你可以使用boost :: weak_ptr. using boost::shared_ptr;using boos
如果我有一个占有其中一个参数的函数,那么当我用Boost. Python公开该函数时,是否应该使用任何调用策略?

void func(MyClass* obj)
{
    // Code that takes possession of `obj`
}

解决方法

我想你可以使用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
}

基本上,这是boost :: weak_ptr文档中提供的示例.
这是reference.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读