Reputation: 134
When using __forceinline or inline inside of a class do I have to include the definition inside of the header file in MSVC? I've heard mixed opinions on this that vary through different compilers.
Example 1:
//some_class.hpp
class some_class
{
public:
__forceinline void some_function();
inline void other_function();
};
//some_class.cpp
void some_class::some_function() { }
void some_class::other_function() { }
Example 2:
//some_class.hpp
class some_class
{
public:
__forceinline void some_function() { }
inline void other_function() { }
};
Upvotes: 1
Views: 2670
Reputation: 37599
In MSVC leaving function definition in .cpp file causes unresolved external symbol
error when linking if function was previously explicitly declared as inline
, __inline
or __forceinline
. So I guess one must put function definition into header. Which makes sense because in order to actually inline the function it's body must be available for compiler.
Upvotes: 1