8.1 concept of function Overloading
1. What if a C ++ program needs to call a compiled C function?
Void Foo (int x, int y );
After the function is compiled by the C compiler, the name of the function in the library is _ Foo, while the C ++ compiler will generate something like _ foo_int_int
Such names are used to support function overloading and type-safe connections. C ++ programs cannot be compiled because their names are different.
Directly call the C function. C ++ provides a C connection to exchange specified symbols.Extern "C"To solve this problem.
For example:
Extern "C"
{
Void Foo (int x, int y );
Other // other functions
}
Or write it
Extern "C"
{
# Include "myheader. h"
Other // other C header files
}
This tells C ++ to compile the interpreter. The function foo is a C connection. You should find the name _ Foo in the library instead
_ Foo_int_int. The C ++ compiler developer has processed the header file of the C standard library as extern "C", so
We can use # include to directly reference these header files.
2. Note that not two functions with the same name can constitute an overload.
Overload (the number or type of parameters are different)
The name of the global function and the member function of the class is not counted.Overload because the function has different scopes.For example:
Void print (response); // global function
Class
{Signature
Void print (member); // member function
}
Whether the parameters of the two print functions are different, if a member function of the class calls a global function
Print. to be different from the member function print, the ':' flag should be added when the global function is called. For example
: Print (member); // indicates that print is a global function rather than a member function.