In order to reduce the compilation time of a fairly large framework at work I was considering moving class method definitions in .h files to their associated .cpp file if they were either very large or required includes to compile that could be moved to the associated .cpp file. For clarity, below is a contrived example (although Foo::inc
is a tiny method)
main.cpp:
#include "Foo.h"
int main(int argc, char** argv) {
Foo foo(argc);
foo.inc();
return foo.m_argc;
}
Foo.h before (no need for Foo.cpp yet):
class Foo {
public:
int m_argc;
Foo (int argc) : m_argc(argc) {}
void inc() { m_argc++; }
};
Foo.h after:
class Foo {
public:
int m_argc;
Foo (int argc) : m_argc(argc) {}
void inc();
};
Foo.cpp:
#include "Foo.h"
void Foo::inc() { m_argc++; }
A long time ago a coworker mentioned that there may be cases where this can cause run time performance to slowdown. I was looking for this case on Google but could not seem to find it, the accepted answer to this question is the closest I could find but it does not give the case, just a mention that it can happen: Moving inline methods from a header file to a .cpp files
On a side note, I am not interested in the case where a method explicitly uses inline
, the answer I linked above was just the closest I could find to what I was looking for
What case (if any) could cause a run time slowdown?