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 }
  • 相关阅读:
    Internal error:1058 解决方法
    bat抓取文件名
    linux 删除含斜杠的文件的方法
    openoffice启动和自动启动设置(centos)
    Qt-OpenCV使用CMake和MinGW的编译安装及其在Qt配置运行
    MEMS传感器介绍
    嵌入式通信协议-IIC和SPI
    电子设计中-电源地,信号地,大地等知识点总结
    Flash存储器-读写原理及次数
    Qt -在应用程序中嵌入Web内容之环境搭建
  • 原文地址:https://www.cnblogs.com/borter/p/9406497.html
Copyright © 2011-2022 走看看