D
Dilip
This must be fairly straightforward as I used to do this quite often
in C++ but I seem to be missing something really obvious. How do I
force the code to call Foo.DoThis() inside Foo.CallIntoDoThis(), even
though the current instance is of type Bar (and hence the call always
dispatches to Bar.DoThis())?
public abstract class Baz
{
public abstract void DoThis();
}
public class Foo : Baz
{
public override void DoThis()
{
Console.WriteLine("Foo.DoThis");
}
public void CallDoThis()
{
DoThis();
// how do I force a call to Foo.DoThis() here???
((Foo)this).DoThis(); // this doesn't work
}
}
public class Bar : Foo
{
public override void DoThis()
{
Console.WriteLine("Bar.DoThis");
}
public void CallIntoFoo()
{
CallDoThis();
}
}
class Program
{
static void Main(string[] args)
{
Bar b = new Bar();
b.CallIntoFoo();
}
}
in C++ but I seem to be missing something really obvious. How do I
force the code to call Foo.DoThis() inside Foo.CallIntoDoThis(), even
though the current instance is of type Bar (and hence the call always
dispatches to Bar.DoThis())?
public abstract class Baz
{
public abstract void DoThis();
}
public class Foo : Baz
{
public override void DoThis()
{
Console.WriteLine("Foo.DoThis");
}
public void CallDoThis()
{
DoThis();
// how do I force a call to Foo.DoThis() here???
((Foo)this).DoThis(); // this doesn't work
}
}
public class Bar : Foo
{
public override void DoThis()
{
Console.WriteLine("Bar.DoThis");
}
public void CallIntoFoo()
{
CallDoThis();
}
}
class Program
{
static void Main(string[] args)
{
Bar b = new Bar();
b.CallIntoFoo();
}
}