[C++-sig] Overriding operator= in boost python
Stefan Seefeld
seefeld at sympatico.ca
Fri Aug 4 16:46:31 CEST 2006
Will Lee wrote:
> Hi,
>
> Is there any way to wrap the operator= for a C++ assignment operator in
> boost python? The documentation on operators doesn't seem to allow that (
> http://www.boost.org/libs/python/doc/v2/operators.html). Essentially, I
> would like to do the python equalivalent of:
>
> class A;
>
> class B : public A;
>
> I then have:
>
> B& operator=(const A& a)
> {
> // assign A to B
> }
>
> So that I can do (say bHolder is a class that contains a B instance):
>
> a = A();
> bHolder.b = a;
The statement
c.b = a
in python will call c's '__setattr__' method, not, as in C++, c.b's
assignment operator. This is because the above changes the binding
of 'c.b', not the state of the object 'c.b' refers to.
Regards,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig
mailing list