摘要: 引用的本质 本质:引用的本质在c++内部实现是一个指针常量 示例: #include <iostream> using namespace std; //发现是引用,转换为 int* const ref = &a; void func(int& ref){ ref = 100; // ref是引用, 阅读全文
posted @ 2020-08-23 05:10 flyingswallow 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 引用做函数返回值 作用:引用可以作为函数的返回值存在 注意:不要返回局部变量的引用 用法:函数调用可以做左值 示例: #include <iostream> using namespace std; //返回局部变量引用 int& test01() { int a = 10; //局部变量 retu 阅读全文
posted @ 2020-08-23 05:07 flyingswallow 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 引用做函数参数 作用: 函数传参时,可以利用引用的技术让形参修饰实参 优点: 可以简化指针修改实参 示例: #include <iostream> using namespace std; //1.值传递 void mySwap01(int a, int b) { int temp = a; a = 阅读全文
posted @ 2020-08-23 04:57 flyingswallow 阅读(93) 评论(0) 推荐(0) 编辑