Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!ucsd!helios.ee.lbl.gov!ux1.lbl.gov!beard From: beard@ux1.lbl.gov (Patrick C Beard) Newsgroups: comp.lang.c++ Subject: Re: Resolving an Overloaded Function Call Keywords: overloading Message-ID: <5545@helios.ee.lbl.gov> Date: 3 May 90 17:34:59 GMT References: <35925@think.Think.COM> <1990May3.030546.1885@agate.berkeley.edu> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux1.lbl.gov (Patrick C Beard) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 31 X-Local-Date: 3 May 90 10:34:59 PDT In article <1990May3.030546.1885@agate.berkeley.edu> c60c-2ca@e260-2a (Andrew Choi) writes: #In article <35925@think.Think.COM> simons@think.com (Joshua Simons) writes: #> #> I have a question about resolving overloaded function calls in #>C++. In Lippman's book, 'The C++ Primer' there is an example on page 155 #>which says that the following function call: #> #> print( 'a' ) ; #> #>exactly matches the overloading: #> #> extern void print( char ) ; #> #> Is this an error? I don't know C++, but in C the type of the #>expression 'a' is 'int' not char so I don't see how this could be an #>exact match. Is C++ different from C in this regard? # # No, this is not an error. In C++ version 2.0, a character #literal/variable is considered to match perfectly with a formal #parameter of type `char'. It will only considered to match #an `int' (and higher derived type) if a perfect match is not found. To clarify the point, yes, C++ is different from C in this regard. A character literal is of type "char". This was introduced for exactly this reason: to permit more precise argument type matching for the resolution of which overloaded function to call. ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. "..............Good day!" - Paul Harvey - -------------------------------------------------------------------------------