Hi,
I have the following code, I am not sure why the compiler allow it to pass, I think I have double defined the function average,i have another file which has this function average defined as well; if it is a variable, it should spit the error, isn't it? Even it is not spitting the error, why it takes the first one not the second?
Thanks for the help!
The keyword "extern" is expecting the function from a file, and polymorphic rules of c++ make two different functions from that, since they have two different origins.
Since you didn't import any other library for your "extern" one, it becomes not used. If it was present in an external file, the compiler would spit back something about an ambiguous reference if they were in the same namespace.
The extern declaration, doesn't actually declare a function. It is simply a hint to the compiler that you will be using a function declared in another compilation unit that isn't visible at the moment, so the compiler doesn't complain. You didn't actually have a function in another compilation unit with the same signature as the one you defined here, so no ambiguity error.