To reduce the compilation time of a fairly large structure at work, I considered defining class class methods in .h files for their associated .cpp file, if they were either very large or required to compile, which could be transferred to the associated .cpp file . For clarity, here's a far-fetched 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 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 colleague mentioned that there may be times when this can lead to a slowdown in performance at runtime. I searched this case on Google, but didnβt seem to find it, the accepted answer to this question is the closest I could find, but itβs not, just mentioning that this can happen: Moving inline methods from a file header to .cpp files
On the side of the note, I am not interested in the case where the method explicitly uses inline , the answer I linked above was the closest I could find what I was looking for
In which case (if any) can slowdowns occur?
source share