You pass in std::deque::push_back. Looking at a reference, you can see there are two overloads:void push_back( const T& value );void push_back( T&& value ); // (since C++11) C ++ 11添加了新的重载.因此,将指向它的指针作为参数传递将变得无效.对于push_front也是如此.请注意,即使在C ++ 11之前,也允许实现添加自己的重载 [需要引用] .C++11 added a new overload. Therefore, passing a pointer to this as an argument becomes invalid. Likewise for push_front. Note that even before C++11, implementations are allowed to add their own overloads[citation needed].您可以将其转换为适当的类型:You can cast it to the appropriate type:.def("push_back" ,static_cast<void(DequeUInt64::*)(DequeUInt64::const_reference)>(&DequeUInt64::push_back)).def("push_front" ,static_cast<void(DequeUInt64::*)(DequeUInt64::const_reference)>(&DequeUInt64::push_front))我强制转换它,而不是根据STL的不帮助编译器明确指定模板参数谈话.I cast it rather than specify the template argument explicitly per STL's Don't Help the Compiler talk.根据Tanner的评论,如果先将lambda强制设置为函数指针,则也可以使用该参数:You can also use a lambda if you force it to a function pointer first, per Tanner's comment:.def("push_back" ,+[](DequeUInt64* d, DequeUInt64::const_reference x) { return d->push_back(x); }).def("push_front" ,+[](DequeUInt64* d, DequeUInt64::const_reference x) { return d->push_front(x); }) 这篇关于为什么以下代码使用`c ++ 03`而不是`c ++ 11`进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-25 19:24