(I feel like this must be a duplicate, but I can’t find it).
Consider:
airplane.hpp:
template<class T>
void wings();
void tail();
Now… where to define wings() and tail()? I’d like to define them in the same place; I’d like not to think about the fact that wings() is templated and tail() isn’t. Maybe you’ll see why I sometimes write:
airplane.hpp:
template<class T>
void wings();
void tail();
#ifndef airplane_cpp
#define header
#endif
#include "airplane.cpp"
airplane.cpp:
#define airplane_cpp
#include "airplane.hpp"
template<class T>
void wings() { }
#ifndef header
void tail() { }
#endif
But surely that’s not the best way.
edit: It seems it may be relevant to add that I’m programming on a TI DSP chip, where, according to the docs, the inline keyword has a defined consequence on generated code:
The inline keyword specifies that a function is expanded inline at the point at
which it is called rather than by using standard calling procedures. The
compiler performs inline expansion of functions declared with the inline
keyword.
You can define all the functions in the header if you make them
inline: