I've got a real situation which can be summarized in the following example:
template< typename ListenerType >
struct Notifier
{
void add_listener( ListenerType& ){}
};
struct TimeListener{ };
struct SpaceListener{ };
struct A : public Notifier< TimeListener >
, public Notifier< SpaceListener >
{
};
struct B : TimeListener{ };
int main()
{
A a;
B b;
a.add_listener( b ); // why is ambiguous?
return 0;
}
Why is not obvious to the compiler that B
is a TimeListener
, and therefore the only possible overload resolution is Notifier< TimeListener >::add_listener( TimeListener& )
?
using Notifier<TimeListener>::add_listener;
(and the other one) instruct A
. Demo – Kermit