Everyone points out the "one definition rule". I'm not going to define any of my stuff in c/cpp files but instead, i'm going to use them for only declarations.
One cpp file:
int add(int x, int y);
The other cpp file:
#include<one.cpp>
int add(int x, int y)
{
return x + y;
}
The other cpp file:
#include<one.cpp>
int main()
{
int result = add(2,2);
}
Basically the same thing, but instead of .h
, i use .cpp
. Difference?
One definition rule is not applicable here.
And yes, last question, why is everyone says that using headers and this technique reduces compile time? How exactly does that work?