operator double() surprise in cxx

From: John Hunter (jdhunter_at_ace.bsd.uchicago.edu)
Date: 04/30/04


Date: Thu, 29 Apr 2004 21:35:51 -0500
To: python-list@python.org


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