Sign in to follow this  

making virtual function inline

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

Virtual functions can't be inline because they are always called via a function pointer, and a function pointer must point to a real function.

The compiler generally ignores the inline keyword when it thinks it's smarter than you about optimizations, which is often (it often actually is smarter, but not always). Each compiler is different, but they tend to ignore it for functions over a certain size, recursive functions, and inline functions that call each other too many times (causing the inline expansion to build up to be over that certain size).

If you're using the Microsoft compiler, pull up the help on #pragma, and look at auto_inline, inline_depth, and inline_recursion.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buzz1982
can we make a virtual function inline?


yes you can always indiciate to the compiler to try and inline.

Quote:
Original post by Buzz1982
also what are the conditions when compiler ignores the inline keyword & does not make the functions inline?


probably non-trivial cases which probably means most of the time but its context & implemenation dependant.

Really thou if your member function is trivial and its something like an accessor method i don't see why it needs to be overridable by sub-types.

If this isn't the case then i wouldn't worry about it so much if it can't be inlined then the overhead probably isn't as bad as you may think it to be, just that one level of indirection is proabably worth 1000 times more than that little performance you lose in terms of flexiablity.

Share this post


Link to post
Share on other sites

This topic is 4840 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.

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