I am having trouble inlining member functions. My code is as follows:
Main.cpp
#include "Foo.h"
int _tmain(int argc, _TCHAR* argv[])
{
Foo foo;
int a = foo.myInlinedFunc(2);
}
Foo.h
class Foo
{
public:
Foo(void);
~Foo(void);
inline int myInlinedFunc(int value);
};
Foo.cpp
#include "Foo.h"
Foo::Foo(void)
{
}
Foo::~Foo(void)
{
}
int Foo::myInlinedFunc(int value)
{
return value * value;
}
I get the following error:
Tester.obj : error LNK2019: unresolved external symbol "public: int __thiscall Foo::myInlinedFunc(int)" (?myInlinedFunc@Foo@@QAEHH@Z) referenced in function _wmain 1>E:\Debug\Tester.exe : fatal error LNK1120: 1 unresolved externals
I have searched google for answers, but the only answers that show up, tells me that I should put the inline keyword in the header-file where it already is.
inline
you promised to make the definition available in the same translation unit, then failed to make good on that promise. What did you expect? – ildjarn