Linking errors from inherited inline functions
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.
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.
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).
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
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement