By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,529 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

operator double() surprise in cxx

P: n/a

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

Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Le Thu, 29 Apr 2004 21:35:51 -0500, John Hunter a écrit*:

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]) );


everything that looks/tastes/sounds like a function declaration is (even
with parameters.

Jul 18 '05 #2

P: n/a
>>>>> "Benoît" == Benoît Dejean <bn********@ifrance.com> writes:

Benoît> Le Thu, 29 Apr 2004 21:35:51 -0500, John Hunter a écrit*:
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]) );


Benoît> everything that looks/tastes/sounds like a function declaration
Benoît> is (even with parameters.

Is it really a bug in g++? No matter how I look at

Py::Float(rect[0])

it does not look like a type "Py::Float*" that is indicated by the error
message. Perhaps it looks like a (Py::Float (*) (rect*)) if g++ think that
rect is a type instead of a variable, but does it really know some type
called rect, and if not, why no error about unknown type on the "function
declaration"?

Regards,
Isaac.
Jul 18 '05 #3

P: n/a
Isaac To wrote:
>> "Benoît" == Benoît Dejean <bn********@ifrance.com> writes:
Benoît> Le Thu, 29 Apr 2004 21:35:51 -0500, John Hunter a écrit*: >> 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]) );

Benoît> everything that looks/tastes/sounds like a function declaration
Benoît> is (even with parameters.

Is it really a bug in g++?


No.
No matter how I look at

Py::Float(rect[0])

it does not look like a type "Py::Float*" that is indicated by the error
message.


As a declaration, it's a zero-length array of Py::Float, with a
parenthesized declarator, i.e. the same as

Py::Float rect[0];

As a parameter declaration, it's equivalent to

Py::Float *rect;

because of the way C++ handles arrays.

Jeremy.
Jul 18 '05 #4

P: n/a
>>>>> "Jeremy" == Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:

Jeremy> As a declaration, it's a zero-length array of Py::Float, with a
Jeremy> parenthesized declarator, i.e. the same as

Jeremy> Py::Float rect[0];

Ah right, thanks for pointing that out.

Regards,
Isaac.
Jul 18 '05 #5

P: n/a
>>>>> "Benoît" == Benoît Dejean <bn********@ifrance.com> writes:
double l( Py::Float(rect[0]) ); double b( Py::Float(rect[1]) );


Benoît> everything that looks/tastes/sounds like a function
Benoît> declaration is (even with parameters.

Interesting.

So you are saying I can do

double l(1);

because this could not be a function declaration so the double
constructor is called with an integer argument, but in

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

the compiler thinks I am declaring a function l that takes Py::Float*
as an argument and returns a double? Hmm. This line was inside a
class method -- I didn't think you could declare functions in a class
method....

Still confused, but perhaps on the road to enlightenment.

JDH

Jul 18 '05 #6

P: n/a
John Hunter wrote:
>>"Benoît" == Benoît Dejean <bn********@ifrance.com> writes: >> double l( Py::Float(rect[0]) ); double b( Py::Float(rect[1]) );

Benoît> everything that looks/tastes/sounds like a function
Benoît> declaration is (even with parameters.

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

the compiler thinks I am declaring a function l that takes Py::Float*
as an argument and returns a double?


Exactly
Hmm. This line was inside a
class method -- I didn't think you could declare functions in a class
method....
Well, you can declare a function nearly everywhere in fact.
Still confused, but perhaps on the road to enlightenment.


Try that :

double l(( Py::Float(rect[0]) ));
Jul 18 '05 #7

P: n/a
Le Fri, 30 Apr 2004 15:50:50 +0200, Christophe Cavalaria a écrit*:
John Hunter wrote:
>>>"Benoît" == Benoît Dejean <bn********@ifrance.com> writes:
Benoît> everything that looks/tastes/sounds like a function
Benoît> declaration is (even with parameters.
Exactly


BS « faced » this problem in a pre-Kona paper

http://anubis.dkuug.dk/JTC1/SC22/WG2...2003/n1509.pdf

this mostly because of the C-style where you declared function nearly
everywhere....

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.