• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

inherited Functions

//SOLVED//

Ive been trying to make a program and my basic idea was to create a base class to handle simple input and then create inherited classes to handle diffrent situations/scenes.

This is my base class

class gameBase
     {
     public:
     gameBase();
     ~gameBase();
     int id;
     int shutdown;

     void drawframe(CGapiSurface& backbuffer);
     void inputclick(POINT & p);
     void inputdown(DWORD &dwKey, GDKEYLIST& keylist);
     private:
     };
//******************************
and this is my inherited class

class gameIntro : public gameBase
     {
     public:
     gameIntro();
     void drawframe(CGapiSurface& backbuffer);
     private:
     linefx letterfx;
     };
//******************************

And in the main class i define it as

gameBase * master;
//******************************

And then set it to

master = new gameIntro();
//******************************

When i call the drawframe function it uses the base class function.  How can i get it to use the inherited function instead?
0
slashandburn
Asked:
slashandburn
1 Solution
 
slashandburnAuthor Commented:
Nevermind i solved it.  I found the answer on http://www.gotw.ca/gotw/005.htm
0
 
skypalaeCommented:
One more thing. If you override virtual function it doesn't mean that you can't call its base form. For example you can declare

class Base {
  virtual void drawFrame (Buffer &buffer) {
    buffer.initBufferSomehow ();
  }
};

class Derived : public Base {
  virtual void drawFrame (Buffer &buffer) {
    // you should allways do the base class call
    Base::drawFrame (buffer) ;

    buffer.initBufferAnotherway () ;
  }
};

etc.

main () {
  Buffer buffer ;

  Base b ;
  Derived d ;

  // this is classic example, same as in your found article
  b.drawFrame (buffer) ;
  // except it initializes the buffer in standard (base) way and then in extended (derived) way
  d.drawFrame (buffer) ;

  // but you can call base function over the derived object too
  // although you'd be carefull wit this, because some initializations required for d would be ommited
  d.Base::drawFrame (buffer) ;
}

Hope this cleared the function overloading bit more.
0
 
tinchosCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 
Computer101Commented:
PAQed, with points refunded (50)

Computer101
E-E Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now