From: Vladimir Grigoriev on

"nomad" <nomad(a)discussions.microsoft.com> wrote in message
news:E1D858EF-2358-47BE-9458-DDA3D146C7BA(a)microsoft.com...
>> > (void) b.F(3);
>>
>> This cast is completely unnecessary.
>
> True, but I like to indicate that I know there's a return value but that
> I'm
> explicitly ignoring it.

It is a bad practise. It is obvious that the return value of b.F( 3 ) is
ignored because you don't assign it to any variable. However in general
using casting force a compiler to generate additional code for the casting.

> Well, I checked the FAQ for inheritance issues, but missed that one. If
> the
> compiler had given me a 'derived f(char) hides base::f(double)' error,
> I'd've
> known what was going on. I'd forgotten about C++'s silly failure to
> resolve
> overloads across scopes.
>

You can resolve overloads across scopes if you make corresponding names
visioble inside class B by means of using statement.

Vladimir Grigoriev


From: Alex Blekhman on
"nomad" wrote:
> Anyone have any idea why the code below fails to compile? I get
> the following message when I try:
>
> error C2660: 'B::F' : function does not take 2 arguments.'
>
> Clearly, B should inherit int F(int, int) from A, the function
> declaration is not ambiguous in any way, so it seems to me that
> I should be able to call it, yet the compiler refuses to allow
> me to do it. If I explicitly reference it (i.e., A::F(x, 3)
> instead of this->F(x, 3)), it works fine.

In addition to other replies it is helpful to remember three main
steps in function call resolution:

1. Name lookup in available scope. If there is no name found in
the current scope, then compiler continues searching in enclosing
scope and so on until the name will be found. It is in this step
the `B::F' virtual function is found and inserted in candidates
list for a call.

2. Overload resolution. Here compiler goes through candidates list
and picks the best match for the call based on function signature.

3. Access rights check. Finally compiler checks whether function
is accessible from current point of call (public, protected,
private).

Bearing these simple rules in mind will make the above compilation
error less non-intuitive.

HTH
Alex