Roman Yakovenko wrote:
> On 9/21/06, Roman Yakovenko <rom...@gm...> wrote:
>> > a = Vector(1,2,3) # this will be a Vector_wrapper instance
>> > b = Vector.zero # this will be a Vector instance
>> > c = a+b # fails
>> >
>> > I don't know exactly what happens here inside Boost.Python, but my
>> guess
>> > would be that the addition is only defined between two *wrapper*
>> classes
>> > and not between a wrapper class and the original class.
>> >
>> > I've experienced such things before with other libraries which is why
>> > I'm only creating wrapper classes when it is absolutely necessary.
>>
>> This is a valid point, that I should check.
>
> Do you mind to post small test case that reproduce the error?
> Also, before you do this, can you check whether redefine_operators = True
> solves the problem?
This flag hasn't had an influence on the generated code.
Here is an example that demonstrates the problem:
// testlib.h
struct Vector
{
double x;
static const Vector one;
Vector(double ax) : x(ax) {}
Vector operator+(const Vector& other) { return Vector(x+other.x); }
virtual void trigger_wrapper() {}
};
// testlib.cpp
#include "testlib.h"
const Vector Vector::one = Vector(1);
Then, in Python the following line fails:
v = Vector(3)+Vector.one
This produces the following TypeError exception:
TypeError: unsupported operand type(s) for +: 'Vector' and 'Vector'
If you comment out the trigger_wrapper() method everything works fine.
- Matthias -
|