-2

I have the signature of the function in my .hpp file and the definition in my .cpp file.

I get a linker error every time I try this, but it goes away and works just fine as soon as I remove the word 'inline'.

  • 2
    Please include a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Eli Sadoff Oct 25 '16 at 19:24
  • Short answer: you do not – Slava Oct 25 '16 at 19:25
  • The whole point of `inline` is to allow you to place the function definition in the header. If you are trying to use `inline` to tell the compiler to inline the function, don't worry about it; modern compilers will inline functions that they deem appropriate, regardless of whether or not you give the `inline` keyword. – 0x5453 Oct 25 '16 at 19:41

1 Answers1

1

An inline function must be defined in every translation unit in which it is odr-used. If you want the function to be inline, you need to define it in the header. If you want to declare it in the header and define it in the .cpp file, then don't mark it inline.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312