c# Generic overloaded method dispatching ambiguous
Posted
by sebgod
on Stack Overflow
See other posts from Stack Overflow
or by sebgod
Published on 2010-05-18T07:11:23Z
Indexed on
2010/05/18
7:30 UTC
Read the original article
Hit count: 257
Hello, I just hit a situation where a method dispatch was ambiguous and wondered if anyone could explain on what basis the compiler (.NET 4.0.30319) chooses what overload to call
interface IfaceA
{
}
interface IfaceB<T>
{
void Add(IfaceA a);
T Add(T t);
}
class ConcreteA : IfaceA
{
}
class abstract BaseClassB<T> : IfaceB<T>
{
public virtual T Add(T t) { ... }
public virtual void Add(IfaceA a) { ... }
}
class ConcreteB : BaseClassB<IfaceA>
{
// does not override one of the relevant methods
}
void code()
{
var concreteB = new ConcreteB();
// it will call void Add(IfaceA a)
concreteB.Add(new ConcreteA());
}
In any case, why does the compiler not warn me or even why does it compile? Thank you very much for any answers.
© Stack Overflow or respective owner