Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Base class method call ?

Base class method call ?

Scheduled Pinned Locked Moved C#
questionhelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chettu
    wrote on last edited by
    #1

    Hi I have Class A with a protected virtual member Method1() and i have another calss Class B inheriting Class A in which i overrided the base class's method Method1() and i also call the base class's Method1() using the base keyword. Now i have another class Class C which inherits Class B and i am overriding Method1(), the problem is now how do i call Class A's Method1() from this class. Class A { protected virtual Method1() {} } Class B : Class A { protected override Method1() { //code. base.Method1() } } Class C : Class B { protected override Method1() { **QUESTION: HOW TO CALL CLASS A's METHOD1() HERE. I dont want to call Class B's Method1() but want to call Class A's Method1()** } } F1! F1! F1!....plzzz:( Regards Chettu.

    S C 2 Replies Last reply
    0
    • C chettu

      Hi I have Class A with a protected virtual member Method1() and i have another calss Class B inheriting Class A in which i overrided the base class's method Method1() and i also call the base class's Method1() using the base keyword. Now i have another class Class C which inherits Class B and i am overriding Method1(), the problem is now how do i call Class A's Method1() from this class. Class A { protected virtual Method1() {} } Class B : Class A { protected override Method1() { //code. base.Method1() } } Class C : Class B { protected override Method1() { **QUESTION: HOW TO CALL CLASS A's METHOD1() HERE. I dont want to call Class B's Method1() but want to call Class A's Method1()** } } F1! F1! F1!....plzzz:( Regards Chettu.

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      You can't do it directly in C# because B has already overridden Method1. You need to have a protected "forwarding" method in class B that does what you want to. Something like class B : A { protected void ForwardMethod() { base.Method1(); } } It's possible in C++ though, A::Method1 will do the job. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      1 Reply Last reply
      0
      • C chettu

        Hi I have Class A with a protected virtual member Method1() and i have another calss Class B inheriting Class A in which i overrided the base class's method Method1() and i also call the base class's Method1() using the base keyword. Now i have another class Class C which inherits Class B and i am overriding Method1(), the problem is now how do i call Class A's Method1() from this class. Class A { protected virtual Method1() {} } Class B : Class A { protected override Method1() { //code. base.Method1() } } Class C : Class B { protected override Method1() { **QUESTION: HOW TO CALL CLASS A's METHOD1() HERE. I dont want to call Class B's Method1() but want to call Class A's Method1()** } } F1! F1! F1!....plzzz:( Regards Chettu.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You can't, and it would suck if you could. Looks like C should derive from A. Christian Graus - Microsoft MVP - C++

        C 1 Reply Last reply
        0
        • C Christian Graus

          You can't, and it would suck if you could. Looks like C should derive from A. Christian Graus - Microsoft MVP - C++

          C Offline
          C Offline
          chettu
          wrote on last edited by
          #4

          Why would it suck.. i have a case where Class C should inherit Class B and not A isn't this a possible scenario... i guess so....The possible solution i have done is have a method in class B which will call the base method in A. This scenario will hold in events.. where calling the base class is mandatory....

          C 1 Reply Last reply
          0
          • C chettu

            Why would it suck.. i have a case where Class C should inherit Class B and not A isn't this a possible scenario... i guess so....The possible solution i have done is have a method in class B which will call the base method in A. This scenario will hold in events.. where calling the base class is mandatory....

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            chettu wrote: i have a case where Class C should inherit Class B and not A isn't this a possible scenario No, because if inheritance is optional, how could you count on it in any way ? Christian Graus - Microsoft MVP - C++

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups