When you say #include "foop.cpp"
, it is as if you had copied the entire contents of foop.cpp
and pasted it into main.cpp
.
So when you compile main.cpp
, the compiler emits a main.obj
that contains the executable code for two functions: main
and foo
.
When you compile foop.cpp
itself, the compiler emits a foop.obj
that contains the executable code for function foo
.
When you link them together, the compiler sees two definitions for function foo
(one from main.obj
and the other from foop.obj
) and complains that you have multiple definitions.