摘要: #include#includeusing namespace std;/* 4.1 封装 成员属性设置为私有的优点: 可以自己控制读写权限 对于写权限,可以检测数据有效性*/class Pers... 阅读全文
posted @ 2021-03-14 18:30 yub4by 阅读(48) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 4.1 封装 访问权限: 公共 public 其中的成员在类内+类外均可访问 保护 protected ... 阅读全文
posted @ 2021-03-14 18:29 yub4by 阅读(52) 评论(0) 推荐(0)
摘要: #include#includeusing namespace std;#define PI 3.14/* 4.1 封装 C++面向对象三大特性:封装、继承、多态 封装意义: 设计类时可以将属性和行为作为... 阅读全文
posted @ 2021-03-14 18:27 yub4by 阅读(62) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 三 函数提高 3.3 函数重载 函数名可以相同以提高复用性 函数重载需满足的条件: 同意作用域下 函数名相同 ... 阅读全文
posted @ 2021-03-14 15:20 yub4by 阅读(31) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 三 函数提高 3.2 函数占位参数 当前学习阶段,占位参数传入后,也接收不到;现在用不到,后续课程用到*/void func(int a, int){ // 第二个int即为占位参... 阅读全文
posted @ 2021-03-14 15:19 yub4by 阅读(56) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 三 函数提高 3.1 函数默认参数*/// 注意,若某个位置已有了默认参数,则从该参数位置往后的每个参数都必须有默认值,例func(int a, int b, int c=30, d=4... 阅读全文
posted @ 2021-03-14 15:18 yub4by 阅读(22) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 二 引用 2.6 常量引用 主要用作修饰形参,防止误操作 函数形参列表中,可以加const修饰形参,防止形参改变实参*/void show_value(int... 阅读全文
posted @ 2021-03-12 15:58 yub4by 阅读(36) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 二 引用 2.5 引用的本质 在C++内部实现了一个指针常量*/void func(int & re){ // 自动转换为:int * const re = &a; ... 阅读全文
posted @ 2021-03-12 15:57 yub4by 阅读(18) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 二 引用 2.4 引用做函数返回值 注意:不要返回局部变量引用 用法:函数调用作为左值*/int & test_1(){ // 引用方式返回 int a... 阅读全文
posted @ 2021-03-12 15:56 yub4by 阅读(51) 评论(0) 推荐(0)
摘要: #includeusing namespace std;/* 二 引用 2.3 引用做函数参数 作用:函数传参时,可以利用引用让形参修饰实参 优点:可以简化指针修改实参(在此方面可以代替指针)*/void swap_1(... 阅读全文
posted @ 2021-03-12 15:55 yub4by 阅读(47) 评论(0) 推荐(0)