摘要: #include <iostream> using namespace std; //函数重载的注意事项 //1.引用作为函数重载 void fun(int& a) //int &a=10;不合法 { cout << "fun(int& a)调用" << endl; } void fun(const 阅读全文
posted @ 2021-09-06 21:08 梦之心 阅读(36) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //函数重载 //可以让函数名相同,提高复用性 //函数重载的满足条件 //1.同一个作用域下 //2.函数名称相同 //3.函数参数类型不同,或者个数不同,或者顺序不同 void func() { cout << " 阅读全文
posted @ 2021-09-06 20:56 梦之心 阅读(33) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //占位参数 //返回值类型 函数名(数据类型){} //目前阶段的占位参数我们还用不到,后面课程中会用到 //占位参数还可以有默认参数 void func(int a, int = 10) { cout << "he 阅读全文
posted @ 2021-09-06 20:44 梦之心 阅读(34) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //函数的默认参数 //如果我们传入了自己的数据,就用自己的数据,如果没有,那么就用默认 //语法 :返回值类型 函数名(形参=默认值){} int func(int a, int b=20, int c=30) { 阅读全文
posted @ 2021-09-06 20:34 梦之心 阅读(45) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //打印数据函数 void showvalue(const int& val) { cout << "val=" << val << endl; } int main() { //常量引用 //使用场景,用来修饰形参, 阅读全文
posted @ 2021-09-06 19:17 梦之心 阅读(42) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; //发现是引用,转换为int * const ref=&a; void func(int& ref) { ref = 100;//ref是引用,转换为*ref=100; } int main() { int a = 1 阅读全文
posted @ 2021-09-06 19:05 梦之心 阅读(27) 评论(0) 推荐(0) 编辑