?
Solved

inherited Functions

Posted on 2003-03-26
4
Medium Priority
?
191 Views
Last Modified: 2010-04-01
//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
Comment
Question by:slashandburn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:slashandburn
ID: 8215196
Nevermind i solved it.  I found the answer on http://www.gotw.ca/gotw/005.htm
0
 
LVL 4

Expert Comment

by:skypalae
ID: 8216087
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
 
LVL 9

Expert Comment

by:tinchos
ID: 9550932
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9594506
PAQed, with points refunded (50)

Computer101
E-E Admin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question