One: Overloading of functions
What do you mean overloaded?
In the same scope, if the names of the 2 functions are the same, and the argument lists are different, they are called "overloads"
form of function overloading
Different shape parameter quantities
such as void Test (int a) and void test (int a, int b)
Different form parameter types
such as void Test (int a) and void Test (double A)
... ...
It is important to note that the following conditions do not belong to the overloaded
void Test (int a) and void test (int b) do not constitute overloads, they represent the same function
void Test (int a) and int test (int a) do not constitute overloading
Second: the implementation principle of function overloading
C + + supports function overloading because the compiler adapts the name of each function
Suppose that the prototype of a function is: void foo (int x, int y);
The function is compiled by the C compiler and is named _foo in the symbol library.
The C + + compiler produces names like _foo_int_int (different compilers may generate different names, but all use the same mechanism, resulting in a new name called "Mangled Name")
_foo_int_int Such a name contains the function name, function parameter number and type information, C + + is this mechanism to implement function overloading
That is, in C + +, the function void foo (int x, int y) is not the same as the symbol generated by the compilation of void foo (int x, float y), which is _foo_int_float.
III: extern "C"
The most important function of extern "C" is to implement c\c++ mixed programming, such as c\c++ function intermodulation
Note: extern must be followed by uppercase C
Variables and functions modified by extern "C" are compiled and concatenated in C language.
That is, the extern "C" void Test (int a, int b) is generated by the compiler function name is _test, no longer a name like _test_int_int
The following notation is equivalent:
extern "C" void Test (int a, int b);
extern "C" void test2 (int a, int b);
Equivalent to
extern "C"
{
void Test (int a, int b);
void Test2 (int a, int b);
}
Because the C language does not support the syntax of extern "C", the general C + + header file's function declaration is so rigorous:
#ifdef __cplusplus
extern "C"
{
#endif
void Test (int a, int b);
void Test2 (int a, int b);
#ifdef __cplusplus
}
#endif
Xcode learns C + + (V, overloads of functions and extern "C")