Can't inline a 1 line void function!
Aug 17, 2013 at 2:15am UTC
I have this simple function in a file:
1 2 3 4 5 6 7 8 9
generic.cpp
#include <iostream>
#include <string>
inline void clearScreen()
{
std::cout << std::string( 30, '\n' ) << std::endl;
}
Now when I simply call this,
clearScreen();
, in main.cpp, I get this:
* warning: inline function 'void clearScreen()' used but never defined [enabled by default]|
* error: undefined reference to `clearScreen()'|
I've also forward declared it in main:
inline void clearScreen();
. It works fine without the inline keyword, not sure why it doesn't like it though?
Last edited on Aug 17, 2013 at 2:16am UTC
Aug 17, 2013 at 2:36am UTC
I'd think you shouldn't have to forward declare it at all. Just include the entire inline definition in the header; if you put it in a separate source file then it can't be inlined.
Aug 17, 2013 at 2:55am UTC
Ok, thanks for clearing that up, that worked.
Cheers!
Last edited on Aug 17, 2013 at 2:59am UTC
Topic archived. No new replies allowed.