Results 1 to 5 of 5

Thread: Inheritance woes [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Inheritance woes [RESOLVED]

    Ok, I have a base class and a derived class.

    I have to be able to 'reset' the fields back to default settings by using a method. The base class has different fields than the derived class but I need to 'reset' all of them from one method. If I create the method in the base class, it will generate a compile error cause those fields don't exist in the derived class. what Is the best solution here?
    Last edited by Andy; Apr 19th, 2004 at 08:50 AM.

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    I guess I would make an overridable sub in the main class, responsible for resetting the fields that it knows about.

    Then override the sub in the derived class, where the first call would be e.g. Mybase.ResetFields. Then I would reset the remaining fields.

    Should you ever derive a third class with even more fields, then it's easy to let the base reset it self, and then just reset the new fields.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ok, so I was on the right track..good

    in the base class, I need a method that resets IT's fields, then, in the derived class, have a method call upon the base class like so: mybase.methodname here...is that right? AND have the derived class' method reset IT's fields as well?

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Exactly.

    This way you can inherit from the derived class as well, and still only add code to reset the new fields.
    And you can inherit form that and from that and from that etc. etc.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Nice....I am finally getting the hang of OOP. I am getting cold chills!!! lol

    Thanks Pax!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width