Qt Creator: “inline function used but never defined” – why?


Question

Why am I getting this warning in Qt Creator: ` inline function ‘bool Lion::growl ()’ used but never defined?

I double-checked my code, and have a declaration

inline bool growl () in Lion (lion.h)

and the corresponding implementation in lion.cpp:

inline bool Lion::growl ()

What’s going on?

EDIT: My assumption has been that it is legal to define the actual inline method in the .cpp file (the inline keyword alerts the compiler to look for the method body elsewhere), or am I mistaken?

I don't want to clutter my header files with implementation details.

1
14
9/14/2009 2:11:12 PM

Accepted Answer

Well, I don't know the exact problem, but for starters:

  • Inline methods are supposed to be implemented in the header file. The compiler needs to know the code to actually inline it.
  • Also using the "inline" keyword in the class declaration doesn't have any effect. But it cannot hurt either.

See also: c++ faq lite

28
9/14/2009 1:59:49 PM

Inline methods are supposed to be implemented in the header file. The compiler needs to know the code to actually inline it.

Except if the inline function is used in the same project, possibly in another file that #include its header.

I miss there is such a restriction for libraries because restricting headers to function prototypes make things more readable.

What about #include-ing the .cpp ?


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon