C++ 重载运算符和重载函数

C++ 重载运算符和重载函数
C++ 允许在同一作用域中的某个函数和运算符指定多个定义,分别称为函数重载和运算符重载。

重载声明是指一个与之前已经在该作用域内声明过的函数或方法具有相同名称的声明,但是它们的参数列表和定义(实现)不相同。

当您调用一个重载函数或重载运算符时,编译器通过把您所使用的参数类型与定义中的参数类型进行比较,决定选用最合适的定义。选择最合适的重载函数或重载运算符的过程,称为重载决策。

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int f(int a )
 6 {
 7     auto int b=0;
 8     static int c=3;
 9     b=b+1;
10     c=c+1;
11     return a+b+c;
12 }
13 
14 int main(int argc, char** argv) {
15     int a=2,i;
16     for(i=0;i<3;i++)
17     cout <<f(a) <<" ";
18     cout <<endl;
19     return 0;
20 }
原文地址:https://www.cnblogs.com/borter/p/9401195.html