Topic: Argument Matching
Author: pkt@lpi.liant.com (Scott Turner)
Date: Sat, 2 Jan 1993 17:38:09 GMT Raw View
John (MAX) Skaller writes:
> Similarly,
>
> f(int*);
> f(const int*);
>
> would not both be allowed. The argument in favour of this
> is that overloading is for two purposes:
>
> A) families of semantically equivalent operations on different types
> e.g. sin(float), sin(complex)
>
> B) [omitted]
>
> In case (A) overloading is desirable because the associated
> 'transparency' renders the program more readable and amenable
> to change of the types (float->complex).
>
> Addition of extra overloaded functions may cause re-binding,
> say sin(double) is added, but it doesnt really matter
> because this doesnt affect the overall semantics.
In the cases where I've seen overloading based on const, there is a very tight
semantic relationship between the overloaded functions, so tight
that they would be the same function except for a difference in
return type. For example,
int & access_the_count (class S&);
const int & access_the_count (const class S&);
in which the overloaded function is providing access to a concrete
or abstract element of an object, and whether the element is const
or not depends on whether the object is const or not.
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA (508) 872-8700
UUCP: uunet!lpi!pkt Internet: pkt@lpi.liant.com
Author: hitz@csi.uottawa.ca (Martin Hitz)
Date: Wed, 26 Jun 91 13:30:09 GMT Raw View
I have been looking for an example for the usefulness of the
"strictly better match" rule in the context of overloading resolution.
The ARM gives one on pages 314-315 (section 13.2), however, I am wondering
if it was possible to rewrite it in a "class-free" manner.
I came up with the following:
int f(void*, void*); // =: 1
int f(const int*, int*); // =: 2
int f(int *, const int*); // =: 3
int i = f(0,0);
The best match sets are {1,3} for the first, and {1,2} for the second argument.
The intersection is {1} (unique), however, 1 is NOT a strictly better match
than 2 (therefore, the call is illegal), because (comparing 1 to 2):
0 -> void* is considered equal to 0 -> const int*
0 -> void* is considered equal to 0 -> int*
although
0 -> int* is considered BETTER to 0 -> const int*
during the first step (computation of "best" match sets).
I have two questions:
1) Is the example valid?
if yes: 2a) Is the argumentation correct?
if no: 2b) Is there a valid "class-free" example?
Thank you!
Martin Hitz@csi.uottawa.ca