Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Actually, it's very well explained in one of the "Effective C++" series.

IIRC, when calling a function, the compiler first looks at the name and only then will try to match the parameters (and choose the right function if there're multiple ones).

So, in that case, it tries to find a function with the name "func" in the Derivate class.. it finds one. Then, it tries to call it and fails because it has the wrong argument. I.e. It won't look at the Base class since it already found a function with the right name.

TL;DR: First = search by name, Second = Match parameters.



This does not seem to explain it completely. Even with "first search by name..." rule, shouldn't the order be:

1. Find "all" the functions accessible bearing the same name. This would include functions available from the base classes.

2. Now match parameters

Seems like the order actually used is:

1. Find the function by name in the specific class (not including base classes)

2. If found, go to 4.

3. Include functions from the next base class (end if no more) and match by name only. Go to 2.

4. Try matching by name.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: