错误:对“CBNET::CBNET(boost::reference_wrapper<const CBNET>::type&)”的调用没有匹配的函数

2024-10-03 15:28:19 发布

您现在位置:Python中文网/ 问答频道 /正文

<>我尝试将Python插件系统包含到C++项目中。 我用了boost(1.54)。在

我可能有一个编译问题,我不知道原因是什么,也不知道可能的解决方法是什么:

In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52:0,
                 from /usr/include/boost/python/object/value_holder.hpp:50,
                 from /usr/include/boost/python/object/class_metadata.hpp:11,
                 from /usr/include/boost/python/class.hpp:23,
                 from /usr/include/boost/python.hpp:18,
                 from includes.h:72,
                 from ghost.h:26,
                 from bnet.cpp:23:
/usr/include/boost/python/object/value_holder.hpp: In instantiation of ‘boost::python::objects::value_holder<Value>::value_holder(PyObject*, A0) [with A0 = boost::reference_wrapper<const CBNET>; Value = CBNET; PyObject = _object]’:
/usr/include/boost/python/object/make_instance.hpp:71:48:   required from ‘static Holder* boost::python::objects::make_instance<T, Holder>::construct(void*, PyObject*, boost::reference_wrapper<const T>) [with T = CBNET; Holder = boost::python::objects::value_holder<CBNET>; PyObject = _object]’
/usr/include/boost/python/object/make_instance.hpp:45:74:   required from ‘static PyObject* boost::python::objects::make_instance_impl<T, Holder, Derived>::execute(Arg&) [with Arg = const boost::reference_wrapper<const CBNET>; T = CBNET; Holder = boost::python::objects::value_holder<CBNET>; Derived = boost::python::objects::make_instance<CBNET, boost::python::objects::value_holder<CBNET> >; PyObject = _object]’
/usr/include/boost/python/object/class_wrapper.hpp:29:51:   required from ‘static PyObject* boost::python::objects::class_cref_wrapper<Src, MakeInstance>::convert(const Src&) [with Src = CBNET; MakeInstance = boost::python::objects::make_instance<CBNET, boost::python::objects::value_holder<CBNET> >; PyObject = _object]’
/usr/include/boost/python/converter/as_to_python_function.hpp:27:61:   required from ‘static PyObject* boost::python::converter::as_to_python_function<T, ToPython>::convert(const void*) [with T = CBNET; ToPython = boost::python::objects::class_cref_wrapper<CBNET, boost::python::objects::make_instance<CBNET, boost::python::objects::value_holder<CBNET> > >; PyObject = _object]’
/usr/include/boost/python/to_python_converter.hpp:88:9:   [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/boost/python/object/class_metadata.hpp:229:80:   required from ‘static void boost::python::objects::class_metadata<T, X1, X2, X3>::register_aux2(T2*, Callback) [with T2 = CBNET; Callback = boost::integral_constant<bool, false>; T = CBNET; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/object/class_metadata.hpp:219:60:   required from ‘static void boost::python::objects::class_metadata<T, X1, X2, X3>::register_aux(void*) [with T = CBNET; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/object/class_metadata.hpp:205:43:   required from ‘static void boost::python::objects::class_metadata<T, X1, X2, X3>::register_() [with T = CBNET; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/class.hpp:507:29:   required from ‘void boost::python::class_<T, X1, X2, X3>::initialize(boost::python::no_init_t) [with W = CBNET; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
/usr/include/boost/python/class.hpp:638:5:   required from ‘boost::python::class_<T, X1, X2, X3>::class_(const char*, boost::python::no_init_t) [with W = CBNET; X1 = boost::python::detail::not_specified; X2 = boost::python::detail::not_specified; X3 = boost::python::detail::not_specified]’
bnet.cpp:4049:31:   required from here
/usr/include/boost/python/object/value_holder.hpp:137:13: error: no matching function for call to ‘CBNET::CBNET(boost::reference_wrapper<const CBNET>::type&)’
             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
             ^
/usr/include/boost/python/object/value_holder.hpp:137:13: note: candidates are:
bnet.cpp:50:1: note: CBNET::CBNET(CGHost*, std::string, std::string, std::string, uint16_t, uint32_t, std::string, std::string, std::string, std::string, uint32_t, std::string, std::string, std::string, char, bool, bool, bool, unsigned char, BYTEARRAY, BYTEARRAY, std::string, std::string, uint32_t, uint32_t, uint8_t)
 CBNET :: CBNET( CGHost *nGHost, string nServer, string nServerAlias, string nBNLSServer, uint16_t nBNLSPort, uint32_t nBNLSWardenCookie, string nCDKeyROC, string nCDKeyTFT, string nCountryAbbrev, string nCountry, uint32_t nLocaleID, string nUserName, string nUserPassword, string nFirstChannel, char nCommandTrigger, bool nHoldFriends, bool nHoldClan, bool nPublicCommands, unsigned char nWar3Version, BYTEARRAY nEXEVersion, BYTEARRAY nEXEVersionHash, string nPasswordHashType, string nPVPGNRealmName, uint32_t nMaxMessageLength, uint32_t nHostCounterID, uint8_t nup )
 ^
bnet.cpp:50:1: note:   candidate expects 26 arguments, 1 provided
In file included from bnet.cpp:33:0:
bnet.h:79:7: note: CBNET::CBNET(CBNET&)
 class CBNET
       ^
bnet.h:79:7: note:   no known conversion for argument 1 from ‘boost::reference_wrapper<const CBNET>::type {aka const CBNET}’ to ‘CBNET&’
make: *** [bnet.o] Error 1

我的加入bnet.cpp公司(剪切):

^{pr2}$

对于任何来源问题,可在此处找到整个提交: https://github.com/OHSystem/OHSystem/commit/2257b168a742d1254847d5668254ea2cde49ff01

问题是我之前有一个名为bncsUtilitInterface.cpp以相同的方式包含更改,并且没有编译错误。在

有什么区别,这个错误的原因是什么?在


Tags: fromstringobjectsobjectincludevalueusrnot
2条回答

你必须分而治之。这项承诺太大了,仅凭一次回顾就无法分析。在

我的直觉是,您应该尝试禁用(注释掉)使用boost::ref的部分,例如:

try 
{ 
    EXECUTE_HANDLER("PlayerDeleted", true, boost::ref(this), boost::ref(player)) 
}
catch(...) 
{ 
    return;
}

(有许多这样的部分)。如果它消除了问题,那么它确认使用boost::ref会导致使用boost::reference_wrapper<...>调用Boost Python“thingies”¹,正如消息所示,这是不受支持的。在

至少对于boost::ref(this)来说,您可以(应该)删除boost::ref似乎很简单,因为this无论如何都是不可变和可复制的。在

对于其他参数,您可能需要使用boost::cref或找到其他方法来传递引用。也许在这里使用引用包装器从一开始就没有必要(我不知道)。在

(请确保不会在预期的引用位置复制参数)

我对这些知之甚少:(

您的类CBNET是可复制的。如果不打算使用class_<CBNET, boost::noncopyable>("BNET", no_init)

如果某个东西是可复制的,那么应该有一个方法来复制,CBNET::CBNET(boost::reference_wrapper<const CBNET>::type&)boost python所要求的签名似乎就是这样的(复制构造函数)。在

但我不确定这是真正的原因。在

相关问题 更多 >