重载的起源

重载的起源

自然语言中,一个词可以有许多不同的含义,即该词被重载了。人们可以通过上下 文来判断该词到底是哪种含义。 “词的重载”可以使语言更加简练。例如“吃饭”的含义 十分广泛,人们没有必要每次非得说清楚具体吃什么不可。别迂腐得象孔已己,说茴香 豆的茴字有四种写法。 在 C++程序中,可以将语义、功能相似的几个函数用同一个名字表示,即函数重载。

这样便于记忆,提高了函数的易用性,这是 C++语言采用重载机制的一个理由。例如示 例函数 EatBeef,EatFish,EatChicken 可以用同一个函数名 Eat 表示,用不同 类型的参数加以区别。

 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 main(int argc, char** argv) {
 6      //声明指针数组
 7     char *colors[]={"Red","Blue","Yellow","Green"}; 
 8     //指向指针的指针变量
 9     char **pt;             
10 
11     //通过指向指针的变量访问其指向的内容
12     pt=colors;
13     for (int i=0;i<=3;i++) {
14         cout<<"pt="<<pt<<endl;
15         cout<<"*pt="<<*pt<<endl;
16         cout<<"**pt="<<**pt<<endl;
17         pt++;
18     }
19     return 0;
20 }
原文地址:https://www.cnblogs.com/borter/p/9406494.html