Click to See Complete Forum and Search --> : Calling parent class function


UnfitElf
September 16th, 2006, 11:21 PM
Hi everyone.

I have a base class which has a pure virtual function called Draw. From this base class i derive several other classes. From from one of these derived classes i derive another class.


Base Class
|
/ \
/ \
Class A Class B
\
Class C

What i would like to be able to do is call Class B's Draw function from Class C's Draw function. This is becuase class c needs to draw exactly what class b draws, but it needs to add a bit more to the drawing as well.

So it would be something like this:

//...
void ClassC::Draw (HDC hdc)
{
// Call Class B's Draw function
//

// Add the extra drawing required for class c
Rectangle(....);
}


Is this possible?
Many Thanks

wildfrog
September 16th, 2006, 11:26 PM
You can call the base class implementation of Draw like this:

void ClassC::Draw (HDC hdc)
{
// Call Class B's Draw function
ClassB::Draw(hdc);

// Add the extra drawing required for class c
Rectangle(....);
}

- petter

UnfitElf
September 17th, 2006, 12:14 AM
I knew that *slaps himself in the head... hard*

Cheers very much Petter :D