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. Newbie: Calling an overriden method from a child class...

Newbie: Calling an overriden method from a child class...

Scheduled Pinned Locked Moved C#
question
4 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.
  • P Offline
    P Offline
    Phillip Hodges
    wrote on last edited by
    #1

    I hope that sounds right? I will explain... I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up. Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'. There are also several versions of 'Z' each doing similar things but with subtle differences. Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...? Thanks in advance, Phil

    "Rules are for the obedience of fools and the guidance of wise men"

    C J 2 Replies Last reply
    0
    • P Phillip Hodges

      I hope that sounds right? I will explain... I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up. Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'. There are also several versions of 'Z' each doing similar things but with subtle differences. Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...? Thanks in advance, Phil

      "Rules are for the obedience of fools and the guidance of wise men"

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Phillip Hodges wrote:

      Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...?

      Yes, just call them. If they are declared as virtual in the base class and override in the derived class then the correct version will be called. i.e. The version defined in the concrete class. That is to say the version of the real object, not its base.


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website

      P 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Phillip Hodges wrote:

        Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...?

        Yes, just call them. If they are declared as virtual in the base class and override in the derived class then the correct version will be called. i.e. The version defined in the concrete class. That is to say the version of the real object, not its base.


        Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website

        P Offline
        P Offline
        Phillip Hodges
        wrote on last edited by
        #3

        Thanks for the quick response... Yeah, I made a silly mistake... It is working fine now... Thanks again, Phil

        "Rules are for the obedience of fools and the guidance of wise men"

        1 Reply Last reply
        0
        • P Phillip Hodges

          I hope that sounds right? I will explain... I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up. Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'. There are also several versions of 'Z' each doing similar things but with subtle differences. Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...? Thanks in advance, Phil

          "Rules are for the obedience of fools and the guidance of wise men"

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          Phillip Hodges wrote:

          lets call it 'X'

          Actually, lets not - it just complicates things and takes therm out of context. Im sure you use a descriptive name in your code (like MyStringCreator or something) so why not use it here to help people understand the context in which you are writing code.

          --- How to get answers to your questions[^]

          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