Sign in to follow this  
Sync Views

object problem

Recommended Posts

Sync Views    139
How do I make it so when I call say the "step1()" function of object "bigball" it also runs the "step1()" function of ball?
class ball
{
	public:
	ball();
	~ball();
	virtual void step1();
	virtual void step2();
	virtual void step3();
	virtual void draw();
};
class bigball : public ball
{
	public:
	bigball ();
	~bigball ();
	virtual void step1();
	virtual void step2();
	virtual void step3();
	virtual void draw();
};

Share this post


Link to post
Share on other sites
Shakedown    230
Do you want bigball::step1() to do something that ball::step1() doesn't? Or do you just want to execute ball::step1() from bigball::step1(), without any added functionality in bigball::step1()?

Share this post


Link to post
Share on other sites
dmatter    4844
It goes a little something like this:

void bigball::step1()
{
// Make a call to the base member function
ball::step1();

// Do other stuff
}


Note that if 'do other stuff' actually equates to 'do nothing' then there's no point in overrriding the step1 function at all.

Share this post


Link to post
Share on other sites
chairthrower    440

with inheritance in c++ style languages you have to do it by explicitly calling the
base behavour method from the inherited one. ie

bigball :: step1()
{
// do the bigball stuff
// ...

// do the default ball stuff
// note that the method is type qualified to get the method we want
ball::step1();
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this