#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;
}
重载的一些东西
最新推荐文章于 2024-09-09 21:20:50 发布