1
我想重載使用Boost.Python的C++類的操作符。如何重載操作符與Boost.Python
根據this,我這樣做是正確的......但我有一堆編譯器錯誤。
這裏是我做了一個簡單的例子,試圖查明問題:
#include "boost/python.hpp"
using namespace boost::python;
class number
{
public:
number(int i) : m_Number(i) { }
number operator+(int i) { return number(m_Number + i); }
private:
int m_Number;
};
BOOST_PYTHON_MODULE(test)
{
class_<number>("number", init<int>())
.def(self() + int());
}
以下是編譯器錯誤:
Error 1 error C2064: term does not evaluate to a function taking 0 arguments c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp 16 BoostPythonTest
Error 2 error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,Fn,const A1 &,const A2 &,const A3 &)' : expects 5 arguments - 1 provided c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp 16 BoostPythonTest
Error 3 error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,Fn,const A1 &,const A2 &)' : expects 4 arguments - 1 provided c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp 16 BoostPythonTest
Error 4 error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,A1,const A2 &)' : expects 3 arguments - 1 provided c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp 16 BoostPythonTest
Error 5 error C2780: 'boost::python::class_<W> &boost::python::class_<W>::def(const char *,F)' : expects 2 arguments - 1 provided c:\users\kevin\documents\visual studio 2008\projects\boostpythontest\boostpythontest\test.cpp 16 BoostPythonTest
我在這裏失去了一些東西?
感謝
你是完全正確的...哎呀。 謝謝! – Kevin