重载的一些东西

#include <iostream>
#include <cstdio>
using namespace std;

//1 double cube(double x)
//2 double cube(double & x)  参数调用时将类型引用和类型本身作为同意特征标。所以编译器分不清哪个是函数原型,将出现错误。
//3 编译器不区分const 和非 const变量。
//4 使用重载的时机,当执行相同的任务,但使用不同的参数时,使用重载。

void init(char *str) {

    cout<<str<<"     "<<"char *str"<<endl;

}

void init( char & str) {

    cout<<str <<"  "<<"const char"<<endl;
}

void work(int a, char b) {

    printf(" int char \n");
}

void work(char b, int a) {

    printf("char b, int a\n");
}

int main()
{
    char p1[20] = "how the weather";
   char p2[20] = "chenjunwei";
   init(p1);
   init(p2);
    work(1, 2.0);
    work(2.0, 1);

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值