Why does this snippet compile (and prints "Fi Fi"):
#include <iostream>
using namespace std;
void f(int) { cout << "Fi" << endl; }
void f(float) { cout << "Ff" << endl; }
struct A
{
void f(int) { cout << "Fi" << endl; }
void f(float) { cout << "Ff" << endl; }
};
int main()
{
f(0);
A().f(0);
}
but this one doesn't?
#include <iostream>
using namespace std;
struct A { void f(int) { cout << "Fi" << endl; } };
struct B { void f(float) { cout << "Ff" << endl; } };
struct C : A, B
{};
int main()
{
C().f(0); // (1)
}
In my understanding, line (1) should call A::f
, but the call is ambiguous instead.