Public Group

# C++ inline and inheritance

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

## Recommended Posts

Greetings, Are there any quirks to using inline on class member functions and (multiple) inheritance that I should know about? Any gotchas that I might not know of? I'm wondering about this because of two reasons. A while back I got stuck for a while when a base class had an overloaded member function. In a derived class I tried to override just one version of the overloaded function, but that didn't work. If you override one member function in a derived class, it will hide the others if you don't also override them. This, along with the fact that you could declare the function inlined in the base class but can choose not to in the derived class (if you are overriding it) or vice versa, it got me worried that there might be a pitfall in there somewhere that I'm not aware of. I took a look at my C++ reference book to see if it had anything to say in depth about class inheritance and inlined member functions and didn't find much other than how to write the syntax. I also didn't see much in the C++ FAQ Lite. Any insight would be greatly appreciated.

##### Share on other sites
Inline keyword denotes optional operation for the compiler. If it cannot inline, it won't.

It's also mostly redundant, compilers inline aggressively as it is, so it's rarely needed to specify it directly.

Quote:
 This, along with the fact that you could declare the function inlined in the base class but can choose not to in the derived class

It doesn't really matter how you declare it. You cannot force compiler to inline a certain function (in C++ at least, compilers may allow it).

But in general, you should go easy with inline, compiler will often know better what to inline, and have better overview of context.

##### Share on other sites
If you want to unhide a name from a base class, just put
using Base::f;

The reason the name is hidden is because name lookup terminates as soon as a suitable name is found, and overload resolution is done in a separate phase. The using directive pulls the other overloads from the base into the derived class namespace, so that they will be found in phase one.

##### Share on other sites
if you are making a polymorphic call it can not be inlined since the correct function to call is not known until runtime.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 76
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632968
• Total Posts
3009585
• ### Who's Online (See full list)

There are no registered users currently online

×