Sign in to follow this  
Sync Views

object problem

Recommended Posts

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
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

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