Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

Linking errors from inherited inline functions

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

As the title describes, I'm getting linker errors, when I'm trying to declare a member function of a class Foo as inline, when this function is used by another member function of class Bar : public Foo. Why is that? If I remove the inline decleration, the linker error will be gone. I'm using MSVC2005, if this is important. I've no idea why I get these errors.

Share this post


Link to post
Share on other sites
Advertisement
I suspect you are defining the function body in Foo.cpp or something similar. If you place the function body in the header file you shouldn't get those linker errors.

Share this post


Link to post
Share on other sites
But why doesn't the linker recognize that the body is inside another file? It does if I don't declare the function as inline. This delimiter would be pointless for OO programming, since a function, that has its body inside the class declaration, is always seen as inline. I would not like to do this, because I don't want other classes to know what this function does (it would result in including much more stuff, that Foo does, but Bar doesn't need to know).

Share this post


Link to post
Share on other sites
Quote:
Original post by SiS-Shadowman
But why doesn't the linker recognize that the body is inside another file?

Because there is no function body - it has been inlined, the function does not exist in effect. Placing the code in the function into the header file will also remedy this error but may be unworkable due to dependancies.

The inline keyword is redundant in most compilers as the compiler will have a better idea as to when the function is better off being inlined and is free to ingnore the inline keyword.

Skizz

Share this post


Link to post
Share on other sites
It's obviously not redundant if it affects the compilation process! It's true that compilers can often inline things themselves, but it's also true that they will use the inline declaration as a hint, especially one saying that no other translation unit will want to access this functionality.

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!