[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]
C++ inheritance and overloading problems
- To: <tribble>
- Subject: C++ inheritance and overloading problems
- From: Ravi Pandya <ravi>
- Date: Mon, 4 Dec 89 23:34:02 PST
- Cc: <xtech>
- In-reply-to: <Eric>,21 PST <8912050617.AA26224@xanadu>
Date: Mon, 4 Dec 89 22:17:21 PST
From: tribble (Eric Dean Tribble)
I don't think they wanted to do anything if they couldn't guarantee
resolution. What does the spec say? (I don't want to try to work out
an impossible example...).
dean
C++ Reference Manual, Volume IV, Section 13.2, Page 87:
"A call of a given function name chooses, from among all functions by
that name that are in scope, the function that best matches the actual
arguments. The best-matching function is the intersection of sets of
functions that best match on each argument. Unless this intersection
has exactly one member, the call is illegal.
For purposes of argument matching, a function with n default arguments
is considered to be n+1 functions with different numbers of arguments.
For purposes of argument matching, a non-static member function is
considered to have an extra argument specifying the object for which
it is called. This extra argument requires a match by either the
object or pointer specified in the explicit member function call
notation." [goes on into even more detail]
So if B is a subclass of A, and we have functions baz(B*,A*) and
baz(A*, B*), then baz(A*, A*) is illegal since each function matches
best on one argument. However, I think the spec says that both of our
examples are legal.
In your example, we have functions B::foo(B*) and A::foo(A*). We call
(B*)->foo(B*) which matches B::foo(B*) best on both arguments. My
example is even simpler, since the number of arguments immediately
determines which function is being referred to. [I believe the
compiler implements your example correctly.]
--ravi