class operators/template problem with boost.python

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

class operators/template problem with boost.python

Marc Janz
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 );"
 
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.
 
Marc
________________________________________________________
Bis 50 MB Dateianhänge? Kein Problem!
http://www.digitaledienste.web.de/freemail/club/lp/?lp=7


-------------------------------------------------------------------------
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/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: class operators/template problem with boost.python

Roman Yakovenko
On Feb 6, 2008 1:01 AM, Marc Janz <[hidden email]> 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,
[hidden email] 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/
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Loading...