Re: class operators/template problem with boost.python

"Roman Yakovenko" <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
On Feb 6, 2008 1:01 AM, Marc Janz <[email protected]> wrote:
> Hello everyone,
>
> i am new to Python and Boost.Python and trying to build a python module from an existing C++ Library.
> I managed to wrap some code but came to a problem exposing operators for the following class, in example the python __add__ method (operator+):
>
> class operand{
> friend operand& operator+(operand&, operand&);
> template friend operand& operator+(operand& Left, const scalar& r);
> };
>
> Note that the parameters are not consts. Unfortunately it was not possible to use
>
> "operand_exposer.def( bp::self * bp::self );"

Your class doesn't contain operator* definition, I guess you meant
"operator+", rigth

> for wrapping. From the error message i get on compiling, i guess it doesnt know which function to use and/or needs functions defined for each datatype i want to use with the template:
>
> error: no matching function for call to  operand::operand(const operand&)
> note: candidates are: ....
>
> How could i get this to work? Btw. I am not able/allowed to modify the existing C++ code. Thanks for your help.

First of all you are posting to the wrong mailing list,
[email protected] is the right one.

You have few choices:

1. operand_exposer.def( "__add__", reference to the operator )

2. If the previous approach doesn't work, you will have to create
wrapper\new operator plus, which will use the already defined one.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.