[C++-sig] Re: C++ Operators and Constructers

David Abrahams dave at boost-consulting.com
Mon May 10 22:35:51 CEST 2004

Stefan Wolf <wolfs at in.tum.de> writes:

> Hi
> I've got the following problem:
> I'm trying to create a python interface to GiNaC (www.ginac.de).
> Mainly I'm interested in the ex class. 
> In GiNaC there exists the operators:
> const ex operator* (ex& lh,ex& rh);
> (same with +,- and /).
> Porting this to python isn't too difficult when dealing only with
> ex-objects. But if you want, for example, multiply to symbols
> (symbol is another class dervived from basic, and ex has a
> constructor ex(const basic& other) ) I get the error:
> TypeError: unsupported operand type(s) for * or mul(): 'symbol' and
> symbol'

What code are you using to wrap that operation?
What compiler are you using?

> Another thing is, if I call for example the subs-method from an
> ex-instance
> (
> GiNaC::ex ex_subs(GiNaC::ex &express, GiNaC::symbol & x, GiNaC::ex &
> y)
> )
> (a wrapper programmed by myself), I get:
> Boost.Python.ArgumentError: Python argument types in
>     ex.subs(ex, symbol, symbol)
> did not match C++ signature:
>     subs(GiNaC::ex {lvalue}, GiNaC::symbol {lvalue}, GiNaC::ex
> {lvalue})
> Which is correct. But I used a 
> implicitly_convertible<GiNaC::symbol,GiNaC::ex>();
> in my .cpp file, so it should convert it automagically, should't it?

No; try it in C++.  An implicit conversion produces an rvalue, which
will never bind to a non-const reference.

> Now, I could write wrapper-functions for all possible combination of
> types, but there should be a shorter way, should't it?

It's not clear.  If you could post a minimal test case that shows
your problems, it would be easier to answer.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list