重载是如何实现的?

重载是如何实现的?

几个同名的重载函数仍然是不同的函数,它们是如何区分的呢?我们自然想到函数 接口的两个要素:参数与返回值。

如果同名函数的参数不同(包括类型、顺序不同),那么容易区别出它们是不同的函 数。

 

 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     struct    books
 8     {
 9     char   title[20];
10     char   author[15];
11     int    pages;
12     float  price;
13     } ;
14     
15     //声明结构变量
16     struct books Zbk={"VC++ ","Zhang",295,35.5}; 
17     books Wbk;  
18 
19     //对结构变量的输出
20     cout<<"Zbk:"<<endl;
21     cout<<Zbk.title <<endl;
22     cout<<Zbk.author<<endl;
23     cout<<Zbk.pages<<endl;
24     cout<<Zbk.price<<endl;
25     cout<<"--------------------"<<endl;
26 
27     //对结构成员的运算
28     Zbk.pages+=10;
29     Zbk.price+=0.5;
30     cout<<"Zbk.pages="<<Zbk.pages<<endl;
31     cout<<"Zbk.price="<<Zbk.price<<endl;
32     cout<<"--------------------"<<endl;
33 
34     //对结构变量的输入输出
35     cout<<"Wbk.title =";
36     cin>>Wbk.title;
37     cout<<"Wbk.author=";
38     cin>>Wbk.author;
39     cout<<"Wbk.pages=";
40     cin>>Wbk.pages;
41     cout<<"Wbk.price=";
42     cin>>Wbk.price;
43     cout<<"Wbk:"<<endl;
44     cout<<Wbk.title <<endl;
45     cout<<Wbk.author<<endl;
46     cout<<Wbk.pages<<endl;
47     cout<<Wbk.price<<endl;
48     cout<<"--------------------"<<endl;
49 
50     //结构变量之间的相互赋值
51     books temp;
52     temp=Wbk;
53     cout<<"temp:"<<endl;
54     cout<<temp.title<<endl;
55     cout<<temp.author<<endl;
56     cout<<temp.pages<<endl;
57     cout<<temp.price<<endl;
58     return 0;
59 }

 

转载于:https://www.cnblogs.com/borter/p/9406497.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值