[alt.religion.computers] C++ overloading

rang@cs.wisc.edu (Anton Rang) (11/12/90)

In article <1990Nov6.002848.3634@clear.com> rmartin@clear.com (Bob Martin) writes:
>By the way, this technique of mangling the function names means that
>
>	int x(int y);
>		and
>	double x(double y);
>
>are completely different functions.  You can declare both of them,
>define them separately and call the proper function by making sure
>that the types are correct.

  OK, something I've been curious about for a while (no C++ manual).
Suppose that you have the two functions above visible, and you write
the code:

	int an_integer;
	double a_double;

	a_double = x(an_integer);

  Will this be resolved to calling the 'int x(int y)' function and
promoting its return value to a double, calling the 'double' function
and promoting the integer argument to a double, or will it be
ambiguous?

  (In other words, are return types and parameters given equal weight
in disambiguating calls?)

	Anton
   
+---------------------------+------------------+-------------+
| Anton Rang (grad student) | rang@cs.wisc.edu | UW--Madison |
+---------------------------+------------------+-------------+

seanf@sco.COM (Sean Fagan) (11/14/90)

In article <RANG.90Nov12103227@nexus.cs.wisc.edu> rang@cs.wisc.edu (Anton Rang) writes:
>  Will this be resolved to calling the 'int x(int y)' function and
>promoting its return value to a double, calling the 'double' function
>and promoting the integer argument to a double, or will it be
>ambiguous?

It becomes 

	double(int x(int))

not ambiguous.

>  (In other words, are return types and parameters given equal weight
>in disambiguating calls?)

Return types are not used in C++ when choosing which function should be
called.

-- 
-----------------+
Sean Eric Fagan  | "*Never* knock on Death's door:  ring the bell and 
seanf@sco.COM    |   run away!  Death hates that!"
uunet!sco!seanf  |     -- Dr. Mike Stratford (Matt Frewer, "Doctor, Doctor")
(408) 458-1422   | Any opinions expressed are my own, not my employers'.

mneerach@iiic.ethz.ch (Matthias Ulrich Neeracher) (11/14/90)

In article <RANG.90Nov12103227@nexus.cs.wisc.edu> rang@cs.wisc.edu (Anton Rang) writes:
>In article <1990Nov6.002848.3634@clear.com> rmartin@clear.com (Bob Martin) writes:
]>By the way, this technique of mangling the function names means that
]>
]>	int x(int y);
]>		and
]>	double x(double y);
]>
]>are completely different functions.  You can declare both of them,
]>define them separately and call the proper function by making sure
]>that the types are correct.

]  OK, something I've been curious about for a while (no C++ manual).
]Suppose that you have the two functions above visible, and you write
]the code:
]
]	int an_integer;
]	double a_double;
]
]	a_double = x(an_integer);
]
]  Will this be resolved to calling the 'int x(int y)' function and
]promoting its return value to a double, calling the 'double' function
]and promoting the integer argument to a double, or will it be
]ambiguous?

int x(int y) will be called and the return value will be promoted.

]  (In other words, are return types and parameters given equal weight
]in disambiguating calls?)

Return types are *ignored* when disambiguating (which has lots of advantages).

Matthias

-----
Matthias Neeracher                                   mneerach@iiic.ethz.ch
   "These days, though, you have to be pretty technical before you can 
    even aspire to crudeness." -- William Gibson, _Johnny Mnemonic_