0

I got the following declaration:

// file MadaPacket.h
class MadaPacket
{
// ....
public:
  inline static bool word_is_header(int w);
}

And as the correspondent declaration:

// file MadaPacket.cpp
#include "MadaPacket.h"

inline bool MadaPacket::word_is_header(int w)
{
    return w == 0xFBBA;
}

MSVC12 builder fails at linkage, with the following reason:

unresolved external symbol "public: static bool __cdecl MadaPacket::word_is_header(int)

Adding static to definition pushes error

'static' should not be used on member functions defined at file scope

Removing inline from definition pushes error

unresolved external symbol "public: static bool __cdecl MadaPacket::word_is_header(int)

I guess I'm misunderstanding some of the definition-declaration relationship.

EDIT

Obviously I'd like to have both the modifiers, if this is possible ofc.

Patrizio Bertoni
  • 2,582
  • 31
  • 43
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Biffen Apr 12 '16 at 12:34
  • A bit general as a "duplicate". – Patrizio Bertoni Apr 12 '16 at 12:37
  • Yeah, it's more of a *here's the answer, you can close this question now*. – Biffen Apr 12 '16 at 12:38

2 Answers2

2

Remove the inline keyword from both places.

The inline keyword should be used only when defining functions in header files that are included from multiple translation units. Well, there are other situations where it can be used too, but here none of them apply.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
-2

You don't have an identical list of modifiers for your definition in your .h file and your .cpp file. Both definitions should be exactly the same for the linker to find them. So I'd first remove 'static' from both and recompile.

Logicrat
  • 4,438
  • 16
  • 22