zoukankan      html  css  js  c++  java
  • 重载是如何实现的?

    重载是如何实现的?

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

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

     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 }
  • 相关阅读:
    信息收集渠道:文本分享类网站Paste Site
    泛域名Wildcard Domain
    分享Kali Linux 2017年第12周镜像文件
    同源策略Same-origin policy
    Wireshark如何选择多行
    GPP加密破解工具gpp-decrypt
    HTTP基础认证Basic Authentication
    HAXM 6.0.5显示不兼容Windows
    分享Kali Linux 2017年第11周镜像文件
    bitShark对Android版本的支持
  • 原文地址:https://www.cnblogs.com/borter/p/9406497.html
Copyright © 2011-2022 走看看