Re: Selection of overloaded function
On Mar 12, 3:29 pm, Fred <fred.l.kleinschm...@boeing.com> wrote:
On Mar 11, 8:06 pm, Michael Tsang <mikl...@gmail.com> wrote:
Fred wrote:
What does the standard say about which overloaded function
to match in this situation:
(Assume classes A and B are defined, and there is an
overloaded operator defined
const A& operator = (const void *);
class Base {
public:
A a;
B b;
virtual void fun( A a& );
This is a syntax error. What do you mean?
Oops - I meant A &a
The real question concerns what is the sequence used to match
overloaded and polymorphed functions.
It seems to be:
1) In Sub class, select the function that matches all non-defaulted
parameter types exactly.
2) If no exact match, see if one exists that can be matched by type-
conversion of non-defaulted parameters.
3) If still no match, repeat (1) and (2) but adding the defaulted
parameters.
4) If still no match (and there were ANY functions by that name
defined in Sub, fail with a 'no match found' error.
5) If there were no functions by that name defined in Sub, then and
only then look for a match in the superclass.
Not at all. The sequence is:
1. Use standard name lookup to find the matching name(s). If
any of the matching name is not a function or a function
template, it is an error.
2. Use ADL to find additional potential names; only functions
and function templates are considered.
3. Do template argument deduction on any function templates in
the resulting set. If deduction fails, throw the function
template out; if deduction is ambiguous, error; otherwise,
add the results of the deduction (which is a function) to
the overload set.
4. If any of the resulting functions has default arguments,
replace it with two or more instances, with and without the
default arguments.
5. Do overload resolution.
--
James Kanze