I have the following code:
class Visitor
{
internal virtual void Visit(Node n) { }
}
class VisitorSpecial : Visitor
{
internal new void Visit(Node n) { }
}
class Base
{
internal virtual void Accept(Visitor v) { }
internal virtual void Accept(VisitorSpecial v) { }
}
class Node : Base
{
internal override void Accept(Visitor v){ v.Visit(this); }
internal override void Accept(VisitorSpecial v){ v.Visit(this); }
}
Is there any reason why the
Accept(Visitor v)
method would be chosen when calling
new Node().Accept(new VisitorSpecial())
Update: OK, my bad, I realized I was using "new" in the visitor instead of override. Now I know why "new breaks polymorphism". This makes my question totally stupid. Thanks for the help.