[C++-sig] operator+(A, B) without B::B() default constructor in boost.python
William Ladwig
wladwig at wdtinc.com
Tue May 19 17:34:49 CEST 2009
It looks to me like you're missing a '()' next to your 'init<>' in the class wrapper for B.
Try changing this:
class_<B,boost::noncopyable>("B",init<int>) //line 19
;
to this:
class_<B,boost::noncopyable>("B",init<int>()) //line 19
;
The only operator that has given me problems is the << operator. I've had pretty good success with the others.
Regards,
Bill
-----Original Message-----
From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler
Sent: Thursday, May 14, 2009 8:16 AM
To: cplusplus-sig at python.org
Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python
Hello,
how can I wrap the following overloaded operator+ using boost.python?
The code as is fails with
>...
>pytest.cpp: In function 'void init_module_pytest()':
>pytest.cpp:19: error: expected primary-expression before '(' token
>...
If I try ".def(self+B())" instead of ".def(self+other<B>())", the error is
>...
>pytest.cpp: In function 'void init_module_pytest()':
>pytest.cpp:17: error: no matching function for call to 'B::B()'
>...
best wishes
Hans
pytest.cpp:
#include <boost/python.hpp>
using namespace boost::python;
class A{
public:
};
class B{
public:
B(int i){};
};
int operator+(const A& a,const B& b){return 42;};
BOOST_PYTHON_MODULE(pytest)
{
class_<A>("A")
.def(self+other<B>()) //.def(self+B()) //line 17
;
class_<B,boost::noncopyable>("B",init<int>) //line 19
;
}
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
More information about the Cplusplus-sig
mailing list