From -2503156522057018670
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,9a5d91576ea14293
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,42ca30940288d269
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-03-04 01:25:23 PST
Xref: sparky comp.lang.c++:5570 comp.std.c++:275
Newsgroups: comp.lang.c++,comp.std.c++
Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh
From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON)
Subject: Re: X to the Y power, how?
Message-ID: <9206419.24970@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <50175@hydra.gatech.EDU> <1992Feb27.135250.25403@ux1.cso.uiuc.edu> <1992Feb27.223558.276@rice.edu> <22292@alice.att.com> <omci1INN8np@agate.berkeley.edu> <9206222.13299@mulga.cs.mu.OZ.AU>
Date: Wed, 4 Mar 1992 09:12:33 GMT
Lines: 53

I must correct my previous posting:

>For example, the following program:

>	#include "exponent.h"
 	#include <stdio.h>

>	int main(int argc, char **argv) {
>		printf("Arg count: %d\n", argc);
>		printf("Program name: %s\n", argv[0]);

>		printf("Yes this REALLY will work: %f\n",
>			2.0 ** 3.0 );
>	}

Unfortunately this will _not_ work (moral: never post code to the net
without running it first, and especially not when you have a high fever and
are not thinking well).

The corrected program needs
		Double x = 3.0;		// you can #define Double double if you
					// really want, but it's pretty nasty.
		printf("Yes THIS really will work: %f\n",
			2.0 ** x );
or
		printf("Yes THIS really will work: %f\n",
			2.0 ** Double(3.0) );

This is because C++ (well, my compiler: I haven't checked the ARM) does not
do the same search for argument conversions when invoking operators operating on
built-in types as it does when invoking functions operating on built-in types.

My original exponent.h had an operator DoubleExponent operator * (Double x).
If you replace it with DoubleExponent indirection(Double x)
and use the expression 2.0 * indirection(3.0),
which I thought was only syntactically different from 2.0 * (*3.0),
then the compiler will correctly find the conversion from double to Double,
but the original expression 2.0 ** 3.0 gives an "Invalid Indirection" error.

Does anybody know why there is this difference between operators and functions?

Thanks, and sorry about my previous post,
	Fergus.

P.S.
Jim Adcock has provided sample code for exponent.h in another post on this
thread.

-- 
Fergus Henderson             fjh@mundil.cs.mu.oz.au      
This .signature VIRUS is a self-referential statement that is true - but 
you will only be able to consistently believe it if you copy it to your own
signature file!


