C++ 错误C2027:使用未定义的类型';boost::python::detail::reference\现有\对象\需要\指针\或\引用\返回\类型<;R>';

C++ 错误C2027:使用未定义的类型';boost::python::detail::reference\现有\对象\需要\指针\或\引用\返回\类型<;R>';,c++,c++11,boost,shared-ptr,boost-python,C++,C++11,Boost,Shared Ptr,Boost Python,我得到错误引用\现有\对象\需要\指针\或\引用\返回\类型 这是密码 boost::shared_ptr<CDB::Basic> GetCdbWrapper(boost::shared_ptr<A> cmd) { return cmd->Cdb(); } } virtual boost::shared_ptr<CDB::Basic> Cdb() { boost::shared_ptr<CDB::Basi

我得到错误引用\现有\对象\需要\指针\或\引用\返回\类型

这是密码

boost::shared_ptr<CDB::Basic> GetCdbWrapper(boost::shared_ptr<A> cmd)
    {
        return cmd->Cdb();
    }
}

virtual boost::shared_ptr<CDB::Basic> Cdb() { 
    boost::shared_ptr<CDB::Basic> CdbObj;
    return CdbObj;
}
boost::shared_ptr<CDB::Basic> GetCdb() { 
    return this->Cdb(); 
}


class_<A, bases<Core::CommandBase>, boost::shared_ptr<A>, boost::noncopyable, >("A",
    ":description:\n",
    boost::python::no_init
)

.def("Cdb", &A::GetCdb,
    ":description:\n",
    return_value_policy<reference_existing_object>()
);
boost::shared_ptr GetCdbWrapper(boost::shared_ptr cmd)
{
返回cmd->Cdb();
}
}
虚拟boost::共享的\u ptr Cdb(){
boost::共享_ptr CdbObj;
返回CdbObj;
}
boost::shared_ptr GetCdb(){
返回此->Cdb();
}
A类,
“:说明:\n”,
boost::python::no_init
)
.def(“Cdb”,&A::GetCdb,
“:说明:\n”,
返回值策略()
);
我可以知道上面的代码有什么问题吗。我得到的编译错误如下

error C2027: use of undefined type 'boost::python::detail::reference_existing_object_requires_a_pointer_or_reference_return_type<R>'
1>        with
1>        [
1>            R=result_t
1>        ]
1>        c:\boost\boost_1_47_0\boost\python\detail\caller.hpp(200) : while compiling class template member function 'PyObject *boost::python::detail::caller_arity<1>::impl<F,Policies,Sig>::operator ()(PyObject *,PyObject *)'
1>        with
1>        [
1>            F=boost::shared_ptr<CDB::Basic> (__thiscall A::* )(void),
1>            Policies=boost::python::return_value_policy<boost::python::reference_existing_object>,
1>            Sig=boost::mpl::vector2<boost::shared_ptr<CDB::Basic>, A &>
1>        ]
错误C2027:使用未定义的类型“boost::python::detail::reference\u现有的\u对象\u需要\u指针\u或\u reference\u返回\u类型”
1> 与
1>        [
1> R=结果\u t
1>        ]
1> c:\boost\boost\u 1\u 47\u 0\boost\python\detail\caller.hpp(200):编译类模板成员函数“PyObject*boost::python::detail::caller\u arity::impl::operator()(PyObject*,PyObject*)”
1> 与
1>        [
1> F=boost::shared_ptr(__thiscalla::*)(void),
1> Policies=boost::python::return\u value\u policy,
1> Sig=boost::mpl::vector2
1>        ]
如文档中所述,返回的对象通过指针或引用引用现有的内部对象:

return\u internal\u reference
[…]允许安全返回指向内部持有的对象[…]的指针和引用,而无需复制引用对象

Python提供了一些概念检查,并且类型通常强调失败的概念。在这种特殊情况下,编译器错误有:

reference_existing_object_requires_a_pointer_or_reference_return_type 互动使用:

>>导入示例
>>>spam=示例。获取\u spam()
>>>断言(类型(spam)为example.spam)

据我所见(不需要进一步了解boost实现),
reference\u-existing\u-object
策略要求返回的对象为指针或引用类型
shared_ptr
既不是指针也不是引用,而是类类型,它由代码中的值返回。虽然,
shared_ptr
是一个资源管理指针包装类,但它本身不是指针。我认为在使用智能指针时不需要
引用现有对象
。谢谢。删除return_value_policy()解决了这个问题。我可以通过保留以下代码绕过编译错误。类(A),:description:\n,boost::python::no_init).def(Cdb),&A::GetCdb,:description:\n);但在构建和安装项目时,我得到了“断言失败C:\Python27\python.exe文件:libs\python\src\converter\registry.cpp。第212行表达式:slot->m_to_python==0错误。这个断言错误可能是上述代码的结果吗?@user3665224我相信断言表明某个类型正在尝试多次注册。例如,如果您有多个
调用。如果您构建了Boost.Python库的发布版本,则会显示一条警告消息,提示您多次注册哪个类的类型信息。那有帮助。!