operator double() surprise in cxx

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Apr 29 22:35:51 EDT 2004


I am using pycxx 5.2.2 to generate some extension code.  I want to
extract some doubles from some python sequences

When I do

  double l( Py::Float(rect[0]) ); 
  double b( Py::Float(rect[1]) ); 

and then later call something like l+b in the extensions code, I get
the compile time error

src/_backend_agg2.cpp:110: error: invalid operands of types `double
   ()(Py::Float*)' and `double ()(Py::Float*)' to binary `operator+'

But

  double l = Py::Float(rect[0]) ; 
  double b = Py::Float(rect[1]) ; 

compiles fine.


I see in the module docs that Py::Float overloads operator double(),
but there is something I am not understanding.  How are these 2 cases
different.  In both cases I expect l and b to be of type double, so
why the difference?  I guess I don't understand exactly what it mean
in C++ to overload operator double().

Thanks, 
John Hunter




More information about the Python-list mailing list