HOW CAN I invoke method through the middle class in the inherit hiberarchy?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eaglebetter
    New Member
    • Nov 2009
    • 1

    HOW CAN I invoke method through the middle class in the inherit hiberarchy?

    class Base1 { public virtual func() ... }
    class Base2 : Base1 { public override func() ... }
    // i already have two class Base2 inherit Base1;
    //and want to inovke Base1::func(),b ut not Base2::func();
    class Base3 : Base2 {
    public override func()
    {
    // i want invoke Base1::func();
    // how can i do?
    }
    }
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    This looks like C++, so I'm not entirely sure. In C# it would be something like
    Code:
    base.base.func();
    So maybe in C++ it would be
    Code:
    base::base::func()
    I'm not sure as I've never worked with Visual C++.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      base.base throws compiler errors for me. base seems to only go up ONE level for me and no way to go up further?
      As for the original problem, I think you need to use different function names?

      You might be able to do something as a type cast though?

      Don't use virtual, use new keywords instead, observe:


      [code=c#]
      public class base1
      {
      public void func()
      {
      MessageBox.Show ("base1");
      }
      }
      public class base2 : base1
      {
      public new void func()
      {
      MessageBox.Show ("base2");
      }
      }
      public class base3 : base2
      {
      public new void func()
      {
      base.func(); //shows "base2"
      base1 o = (base1)this;
      o.func(); //shows "base1"
      }
      }
      [/code]
      Then this call will verify it:
      [code=c#]
      base3 f = new base3();
      f.func();
      [/code]

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        I admit I was just guessing. I've never had to do that.

        Comment

        Working...