[C++-sig] Support for member operators?

Nicodemus nicodemus at globalite.com.br
Sat Mar 1 20:39:01 CET 2003


Hi!

Suppose I have the following:

struct C
{
     C(int x_): x(x_) {}

     int x;

     const C operator+(int o)
     {
         return C(x + o);
     }

};

const C operator*(const C& c, int o)
{
     return C(c.x * o);
}

If I try to expose the operator+ like this:

     .def( self + other<int>() )

I get a compiler error: "no operator "+" matches these operands", while the * 
operator works perfectly:

     .def( self * other<int>() )

Does Boost.Python support member operators?

For now, I'm exposing the operator + like this:

     .def("__add__", C::operator+)

and it works, but I wonder if there's a better way.

Thanks,
Nicodemus.






More information about the Cplusplus-sig mailing list