Let me explain what I want to understand, recently I see these videos from youtube about how the compiler and the linker work.
How C++ works:
https://www.youtube.com/watch?v=SfGuIVzE_Os&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=5
How C++ compiler works:
https://www.youtube.com/watch?v=3tIqpEmWMLI&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=6
How C++ linker works:
https://www.youtube.com/watch?v=H4s55GgAg0I&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=7
In those videos, it is explained what happens when you have functions with the same declaration and definition, but just have examples with static to static functions (that solves the linking error since each function is seen different) and non-static to non-static functions (which gives a linking error since the linker do not know what function are you calling).
However, those videos are just extra information I will explain my doubt. Suppose we want to have to functions with the same declaration but different definition for some reason and we make the next code.
Math.cpp file:
int Multiply(int a, int b) {
return 0;
}
Main.cpp file:
#include <iostream>
int Multiply(int, int);
static int Multiply(int a, int b) {
int result = a * b;
return result;
}
int main() {
std::cout << Multiply(5, 2) << std::endl;
std::cin.get();
}
Running this code, the static Multiply function is called.
How the linker knows what function are you calling on main function?
and with the given code:
How can I call the Multiply function that is on the Math.cpp file from main function having the static version?