Skip to main content
gamedev.net
🔒 Locked

function overloading

Started by MrOffRoad 1 reply 200+ views
Original Post
MrOffRoad
MrOffRoad
Quick question about overloading. I want to overload the base class function but I still need the function to do everything it does in the base class plus a bit more functionality. Without resorting to cutting and pasting can I get the child class function to run the code from the base class function then a bit of code of its own. Can I explicitly call the base class function within the overloading function or what? I hope that makes sense
JY
JY
Yeah:



class A
{
public:
virtual void DoSomething()
{
cout << "Class A";
}
};

class B : public A
{
public:
virtual void DoSomething()
{
A::DoSomething();
cout << " is my daddy!";
}
};



... kinda like that, and the B:: function will then call the A:: function and do a bit more.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
MrOffRoad
MrOffRoad
Thanks JY

Thats just what I was after

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.