摘要: #include#include#includeusing namespace std;/* 4.5.5 关系运算符重载 可以让连个自定义类型的对象进行对比操作*/class Person{public: string name; ... 阅读全文
posted @ 2021-03-16 19:41 yub4by 阅读(21) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.5.4 赋值运算符重载 C++编译器至少给一个类添加4个函数 默认构造函数,无参,函数体为空(4.2.4) ... 阅读全文
posted @ 2021-03-16 19:40 yub4by 阅读(33) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.5.3 递增运算符重载 可通过此实现自己的整型数据 分两种:前置、后置 总结: 前置递增返回引用,后置递增返回值*/cla... 阅读全文
posted @ 2021-03-16 19:39 yub4by 阅读(63) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.5.2 左移运算符重载 可以输出自定义的数据类型*/class Person{public: int a; int b; /... 阅读全文
posted @ 2021-03-16 17:58 yub4by 阅读(41) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.5 运算符重载 对已有运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型 4.5.1 加号运算符重载 实现两个自定义... 阅读全文
posted @ 2021-03-16 17:56 yub4by 阅读(45) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.4.3 成员函数做友元*/class Building;class Goodgay{public: Goodgay(); // 构造声明 voi... 阅读全文
posted @ 2021-03-16 14:49 yub4by 阅读(39) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.4.2 类做友元*/class Building; // 声明Building类,后续会写,防止Goodgay类中引用时报错class Goodgay{pu... 阅读全文
posted @ 2021-03-16 14:48 yub4by 阅读(43) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.4 友元 让一个函数或类可以访问另一个类中的私有成员 关键字friend 三种实现: 全局函... 阅读全文
posted @ 2021-03-16 14:47 yub4by 阅读(65) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.3.4 const修饰成员函数 常函数:成员函数后加const(修饰的是this指针,令指针指向的值也不可修改) 常函数... 阅读全文
posted @ 2021-03-16 12:10 yub4by 阅读(25) 评论(0) 推荐(0)
摘要: #include#include#includeusing namespace std;/* 4.3.3 空指针访问成员函数 C++中空指针是可以调用成员函数的 但是注意有没有用到this指针(有坑) 若用到了t... 阅读全文
posted @ 2021-03-16 12:09 yub4by 阅读(40) 评论(0) 推荐(0)