Jump to content
  • Advertisement
Sign in to follow this  
snooty

Placement of "virtual"

This topic is 4312 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

Hi, Where should the virtual keyword for a function be placed? In base class declaration / function definition? In derived class declaration / function definition?

Share this post


Link to post
Share on other sites
Advertisement
The only place where it is required is the base class declaration; yet it maybe considered good form to place it in the derived class aswell to show it's virtual to users.

Share this post


Link to post
Share on other sites
Quote:
Original post by snooty
Hi,

Where should the virtual keyword for a function be placed?
In base class declaration / function definition?
In derived class declaration / function definition?


In the base class declaration, and optionally in the derived class declaration
Quote:
section 10.3 §2 of the Holy Standard
If a virtual function vf is declared in a class Base and in a class Derived, derived directly or indirectly from Base, a member function vf with the same name and the same parameter list as in Base::vf is declared, then Derived::vf is also virtual (whether or not it is so declared) and it overrides Base::vf.


If you use the virtual keyword on the function definition, you'll get a compiler error.

Regards,

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!