473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

operator double() surprise in cxx


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.c pp: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
7 1562
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
>>>>> "Benoît" == Benoît Dejean <bn********@ifr ance.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
Isaac To wrote:
>> "Benoît" == Benoît Dejean <bn********@ifr ance.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
>>>>> "Jeremy" == Jeremy Yallop <je****@jdyallo p.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
>>>>> "Benoît" == Benoît Dejean <bn********@ifr ance.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
John Hunter wrote:
>>"Benoît " == Benoît Dejean <bn********@ifr ance.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
Le Fri, 30 Apr 2004 15:50:50 +0200, Christophe Cavalaria a écrit*:
John Hunter wrote:
>>>"Benoî t" == Benoît Dejean <bn********@ifr ance.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
10398
by: | last post by:
I have not posted to comp.lang.c++ (or comp.lang.c++.moderated) before. In general when I have a C++ question I look for answers in "The C++ Programming Language, Third Edition" by Stroustrup. However, I've come upon a question that I can neither answer from "The Book" or a Google search (so yes, at least I RTFBed). I'm hoping that someone...
1
3859
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include "BitString.h"
34
6412
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment operator. Here's what I'm trying to do. I've defined class Complex as class Complex { friend ostream &operator<<( ostream &, Complex & ); public:...
15
17933
by: Bart Simpson | last post by:
Can anyone explain how this works. How may I implement this? I want to be able to use the operator on both lhs and rhs of assignment statements. The rhs is a no-brainer (at least I think I got it right): class MyArray { public: MyArray(const size_t size):m_size(size){ arr_ = new double; } ~MyArray(){ if (arr_) delete arr_ ;}
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.