In a library, I have the following in a header:
// button.hpp
class ExtraButtons
{
public:
static inline void show() { setShown(true); }
static inline void hide() { setShown(false); }
static void setShown(bool shown);
};
and the following in a source file:
#include "button.hpp"
void ExtraButtons::setShown(bool shown)
{
}
The library compiles fine. However, when I'm using the library and I include button.hpp, I get this error from the setShown calls in show() and hide():
undefined reference to `ExtraButtons::setShown(bool)'
I can fix the problem by removing the inline from show() and hide() and defining them in the source file, like normal, OR by making setShown inline as well. Why is this the case? Are these the only solutions?
inlinewould have such a big effect. In my experience,inlineis more a reminder to yourself that you expect the function to be compiled inline, rather than something else.inlineis to allow definitions in multiple translation units (which is often necessary for the compiler to be able to inline it). But you're right that that shouldn't make a difference here.bool const &in the error message is a bit suspicious, when the type is justboolin the code. Are you sure you've shown us the exact code you're compiling? Have you changed the header and not recompiled some files that include it?bool const &was a mistake on my part. I had just changed that in the code.