Overloading of C + + functions
Defined
In the same scope, the function name is the same, the function's argument list differs between functions to form an overload relationship, and the function with the same name in different scopes follows the principle of hiding the identifiers
ATTENTION: Overloading has nothing to do with the return value type of a function, because declaring a function requires no return type, so it cannot be used to distinguish which function
An overload is formed between an ordinary function and a normal member function, and an overloaded constant object invokes a regular member function, and a generic object invokes a generic member function
Class a{...
Public:
void Getval () const{...}
void Getval () {...}}
;
int main () {
const a A;
A b;
A.getval (); Constant function
b.getval ();//normal member function
}
Functions in different namespace can also be used in the same scope by the namespace instruction/namespace declaration, thus constituting the overloaded relation
Overloaded functions in different namespaces
#include <iosteam>
using namespace std;
namespace ns1{
void fa (int i) {cout<< "in ns1:i=" <<I<<ENDL;}
namespace ns2{
void Fa (double D) {cout<< "in ns2:i=" <<D<<ENDL;}
int main () {
//Use namespace ns1 using the namespace instruction method
;
using namespace ns2;
FA (a);
FA (3.14);
return 0;
}
Overload matching principle
Full match > Constant conversion/constant matching > Upgrade conversion > Standard conversion > Custom conversion > Ellipsis matching
Note: In programming, as far as possible to achieve a complete match, if it can not exactly match, will generally be based on the above principles to choose
Overload principle
C + + compiler is to change the name of the function, the parameter list information in the underlying function name, so as to achieve the function of overloading, assembly function name in accordance with < scope + RETURN type + function name + parameter list > in the way embodied in the Assembly, Eg:_z4showii:
Thank you for reading, I hope to help you, thank you for your support for this site!