摘要: 1 #include "mainwindow.h" 2 #include 3 #include > 4 5 //重载的三种形式,成员函数重载 6 //友元函数重载,可以使用私有变量以及保护变量 7 //一般函数重载都是公有变量 8 9 class button 10 { 11 QPushButton *p; 12 int x,y; 13 14 f... 阅读全文
posted @ 2018-03-18 23:57 喵小喵~ 阅读(981) 评论(0) 推荐(0) 编辑
摘要: 1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 using namespace std; 5 6 //返回值为类的引用不会调用拷贝构造 7 //拷贝构造要深拷贝,赋值重载(=)也要深拷贝 8 //注意对象如果是在栈上,有生命周期,拷贝栈上的对象需要深拷贝 9 10 class mystring 11 {... 阅读全文
posted @ 2018-03-18 23:05 喵小喵~ 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 非指针,则深浅拷贝都一样,含有指针则内存共享,指针一致,内容一直 深拷贝,指针不一致,内存一直,内存是独享的 赋值重载如果有返回自身类型对象,会调用拷贝构造,需要重载拷贝构造,这一点是必须要注意的,原理是:先操作一个类,再把操作的这个类拷贝到本类中,即使返回(*this),也会调用 (如果返回值是自 阅读全文
posted @ 2018-03-18 18:48 喵小喵~ 阅读(135) 评论(0) 推荐(0) 编辑
摘要: shortsafe operator ++() 先自增再引用 shortsafe operator ++(int) 先引用再自增后面,需要副本(先用副本进行操作,然后再进行自己类的++改变数据)(返回的都是修改后的数据) ()可以把对象名当做括号来操作 代码示例 阅读全文
posted @ 2018-03-18 17:49 喵小喵~ 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 using namespace std; 4 5 class box 6 { 7 private: 8 int x; 9 int y; 10 int z; 11 12 13 public: 14 box() :x(10), y(20), ... 阅读全文
posted @ 2018-03-18 17:28 喵小喵~ 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 using namespace std; 4 5 class mystring 6 { 7 public: 8 char *pstr; 9 int length; 10 mystring():pstr(nullptr),length(0) 11 { ... 阅读全文
posted @ 2018-03-18 12:56 喵小喵~ 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 int num; 8 public: 9 explicit myclass(int data) :num(data) 10 { 11 12 } 13 }; 14 15 void main() 16 { 1... 阅读全文
posted @ 2018-03-18 12:16 喵小喵~ 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 using namespace std; 3 4 //友元函数的主要作用就是访问私有变量 5 class myclass 6 { 7 public: 8 friend class newclass; 9 private: 10 int x; 11 int y; 12 int z; 13 14 15 }; 16 ... 阅读全文
posted @ 2018-03-18 12:07 喵小喵~ 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 using namespace std; 4 5 //友元函数的主要作用就是访问私有变量 6 class myclass 7 { 8 private: 9 int x; 10 int y; 11 12 public: 13 myclass(int a,int b) 14 { 15 ... 阅读全文
posted @ 2018-03-18 11:56 喵小喵~ 阅读(464) 评论(0) 推荐(0) 编辑