I tend to put the body of smaller functions right into the header file foo.h
, not into the separate implementation file foo.cc
, because then the compiler can always see those functions completely and decide to inline them.
Example:
// File "foo.h":
struct Foo {
// ...
int GetCount() const { return count_; }
};
Now any code that uses Foo
sees the whole GetCount
implementation and can decide to inline it.
Is that good practice? If so, do you put slightly larger function definitions into the header file as well?