Searching for a name is a separate phase for resolution overloading.
First, the search for the name begins. This is the process of determining which area this name belongs to. In this case, we must decide whether d.foo means dD::foo , or d.B1::foo , or d.B2::foo . Name search rules do not take into account functional parameters or anything else; these are purely names and domains.
Only after this decision has been made, we then perform overload resolution for various function overloads in the area where the name was found.
In your example, a call to d.foo() will find D::foo() if there was such a function. But they are not there. Thus, working in the opposite direction by regions, he tries the base classes. Now foo can look at B1::foo or B2::foo same way, so it is ambiguous.
For the same reason, you get ambiguity causing unqualified foo(5); inside a member function of D
The effect of the recommended solution:
struct Derived : public Base1, public Base2{ using Base1::foo; using Base2::foo;
this is that it creates the name D::foo and allows you to identify two functions. As a result, d.foo resolves to dD::foo , and then with these two functions that are identified by D::foo , permission overloading can occur.
Note. In this example, D::foo(int) and Base1::foo(int) are two identifiers for one function; but in general, it does not matter for the process of finding names and handling overloads whether they are two separate functions or not.
MM Sep 19 '16 at 2:10 2016-09-19 02:10
source share