Inheritance - Accessing two levels above mine

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Hi,

How can I access a (non-static) member method that is two levels above
mine, from a member method that has the same name?

How can I access C_A0.func() from inside C_A000.func() ???

Is this possible?

Thanks a lot.
Bill


// ----------------------------
namespace Project0
{
public class C_A0
{
public int func()
{
return(1);
}
}

public class C_A00 : C_A0
{
new public int func()
{
return(2);
}
}

public class C_A000 : C_A00
{
new public int func()
{
// How can I access C_A0.func() from here??
// It does not let me write "base.base.func()". I can access the
first "base", but not the second one.
// It does not let me write "C_A0.func()", because that function
is not static.
return(3);
}
}
}
 
Bill said:
Hi,

How can I access a (non-static) member method that is two levels above
mine, from a member method that has the same name?

How can I access C_A0.func() from inside C_A000.func() ???

Is this possible?

Thanks a lot.
Bill


// ----------------------------
namespace Project0
{
public class C_A0
{
public int func()
{
return(1);
}
}

public class C_A00 : C_A0
{
new public int func()
{
return(2);
}
}

public class C_A000 : C_A00
{
new public int func()
{
// How can I access C_A0.func() from here??
// It does not let me write "base.base.func()". I can access the
first "base", but not the second one.
// It does not let me write "C_A0.func()", because that function
is not static.
return(3);
}
}
}


winthin class C_A000.func() you can do this:

( (C_A0) ((C_A00) this) ).func()
 
Family Tree Mike said:
winthin class C_A000.func() you can do this:

( (C_A0) ((C_A00) this) ).func()


That was dumb... Just do this:

((C_A0) this).func();
 
As Mike said you can just type cast "this" to the base class. Note though
that if the method is virtual and overridden this wont work, and trying to
execute a specific base class's implementation of a virtual method (other
than your direct ancestor class) is a sign of a bad design.
 
Thanks to both of you. It worked.
I posted a new message with a sligthly different question, now with
"virtual+override" instead of "new".
 
Back
Top