Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

virtual funtions??

This topic is 2848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a base class which has some base funtions like

virtual void AI();
virtual void Move();


when i inherit from this do i have to include in the .h and .cpp file of the inherited
void AI();
void Move();

some dont have any AI();
is this the only way to do it ?

is there a better way around this ???

Share this post


Link to post
Share on other sites
Advertisement
Hi thedodgeruk.

To inherit from a class you should include its header file.

You generally never include cpp files.

It's not the only way to do it - for example you could do it using composition. Although it's hard to say if it is better or not - it depends on many things.

Share this post


Link to post
Share on other sites
If some of your subclasses don't need to do anything, you can do one of two things:
  1. Provide a default implementation in the base class, which can be simply an empty function
  2. Provide an empty implementation in the subclasses.

Share this post


Link to post
Share on other sites
I think the OP is asking if he has to redefine the methods in the derived class.
This depends on whether they have a definition in the base class.

"some dont have any AI" : then the derivation meaning "is a" is probably incorrect. What are the names of your classes ?

You should show some code. Does your first question come from a compilation error you get ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!