I've seen similar questions asked yet they still do not make sense to my ape brain.
Here is an example. If I declared a function in a header file named Bob.h
: void PrintSomething();
and in the .cpp
file I say: void MyClass::PrintSomething(){std::cout << "Hello";}
. I've seen people in another .cpp
file for example Frank.cpp
, only include the Bob.h
header which just has the declaration (No code inside it) and not the .cpp
with the code but then what blows my mind is when they call the PrintSomething()
function in Frank.cpp
it uses the code from Bob.cpp
and prints "Hello". How? How does it print "Hello" which was added in the .cpp
file when I've only included the .h
file which doesn't say anything about "Hello", its just a declaration? I've looked through the compile process and linking process too but it just doesn't stick.
On top of which if I were to now say in my Frank.cpp
file: void MyClass::PrintSomething(){std::cout << "Bye";}
and included the Bob.h
file in my main.cpp
and called the PrintSomething()
function would it print "Hello" or "Bye"? Is the computer psychic or something? This concept is the one thing I am not grasping in my C++ learning journey.
Thanks in advance.