随笔分类 -  C++

摘要:类中可以包含引用成员,但必须在定义变量的时候默认初始化 引用作用域参数和返回值,避免内存占用 常引用等价于常对象 常引用等价于常对象 完整代码 阅读全文
posted @ 2018-03-17 23:26 喵小喵~ 阅读(113) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 struct point 5 { 6 int a; 7 int b; 8 }; 9 10 class myclass 11 { 12 public: 13 int x; 14 int y; 15 myclass(int n):x(n),y(n) 16 ... 阅读全文
posted @ 2018-03-17 23:11 喵小喵~ 阅读(87) 评论(0) 推荐(0)
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 using namespace std; 5 6 //默认拷贝构造只是值传递,对于数据有效,对于指针则是同一个指向,需要重写一下拷贝构造 7 //类的内部有指针分配内存,需要深拷贝,否则需要浅拷贝 8 class mystring 9 { 10 public... 阅读全文
posted @ 2018-03-17 23:03 喵小喵~ 阅读(105) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 int x; 8 int y; 9 public: 10 myclass() = default; 11 //拷贝构造 12 //myclass(const myclass &my) = defaul... 阅读全文
posted @ 2018-03-17 22:45 喵小喵~ 阅读(112) 评论(0) 推荐(0)
摘要:const常量对象,无法改变数据,只能引用尾部带const方法 类的成员如果是const,可以默认初始化,也可以构造的初始化,不可在构造函数内部初始化 类中的const成员,无法直接修改,可以间接修改 类的成员函数const三种情形:1.返回值const,2.返回常量,3.参数const,可读不可写 阅读全文
posted @ 2018-03-17 17:23 喵小喵~ 阅读(169) 评论(1) 推荐(0)
摘要:1 #include "mainwindow.h" 2 #include 3 4 //创建一个MainWindow类 5 class myclass 6 { 7 private: 8 MainWindow *p; 9 //初始化内存 10 myclass(int i) 11 { 12 p = new MainWindow[i]... 阅读全文
posted @ 2018-03-16 22:50 喵小喵~ 阅读(211) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 //myclass类 5 class myclass 6 { 7 public: 8 int add(int a, int b) 9 { 10 return a + b; 11 } 12 int sub(int a, int b) 13 { 1... 阅读全文
posted @ 2018-03-16 20:04 喵小喵~ 阅读(161) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 int add(int a,int b) 8 { 9 return a + b; 10 } 11 }; 12 13 void main() 14 { 15 myclass my1; 16 ... 阅读全文
posted @ 2018-03-16 18:50 喵小喵~ 阅读(190) 评论(0) 推荐(0)
摘要:面向过程: 创建一个类继承dialog,mydialog,添加两个变量 main.cpp中初始化 dialog.cpp中实现按钮的操作 面向对象: mg.h 1 #ifndef MG_H 2 #define MG_H 3 #include "mydialog.h" 4 5 class mg 6 { 阅读全文
posted @ 2018-03-16 14:27 喵小喵~ 阅读(472) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class man 5 { 6 private: 7 int id; 8 char ch; 9 10 public: 11 //0个参数委托一个参数的构造函数,一个参数的委托两个参数的构造函数构造 12 man():man(1) 13 { 14 15 ... 阅读全文
posted @ 2018-03-15 22:43 喵小喵~ 阅读(114) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 //初始化数据的时候,如果类中引用其他类,需要重写构造函数,int也是类 7 class myclass 8 { 9 public: 10 int x; 11 int y; 12 13 public: 14 myclass(i... 阅读全文
posted @ 2018-03-15 22:25 喵小喵~ 阅读(201) 评论(0) 推荐(0)
摘要:按钮点击获取文本框输入 1 void Dialog::on_pushButton_clicked() 2 { 3 //获取文本输入 4 QString vstr = ui->lineEdit->text(); 5 6 //判断是否转换成功 7 bool isok; 8 //转换 9 int valu 阅读全文
posted @ 2018-03-15 22:13 喵小喵~ 阅读(220) 评论(0) 推荐(0)
摘要:一维数组封装 myArray.h myArray.cpp 1 #include "myArray.h" 2 3 myArray::myArray(initializer_list<int> list) 4 { 5 this->n = list.size();//开辟内存 6 this->p = ne 阅读全文
posted @ 2018-03-15 21:33 喵小喵~ 阅读(409) 评论(0) 推荐(0)
摘要:1 #include "mainwindow.h" 2 #include 3 #include 4 5 //定义一个窗口类 6 class Window 7 { 8 public: 9 MainWindow *p; 10 int x;//大小 11 int y; 12 int cx;//位置 13 int cy; 14 15 pu... 阅读全文
posted @ 2018-03-15 20:42 喵小喵~ 阅读(414) 评论(0) 推荐(0)
摘要:1 //指针数组,每一个指针都是一个MainWindow 2 // MainWindow *w[3][4]; 3 // for(int i=0;imove(i*100,j*100); 9 // w[i][j]->resize(100,100); 10 // w[i][j]->show(); 11 // } 12 //... 阅读全文
posted @ 2018-03-15 19:54 喵小喵~ 阅读(3987) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 using namespace std::placeholders; 5 6 template 7 void show(T t) 8 { 9 cout 16 void show(T t) 17 { 18 cout ; 30 p(... 阅读全文
posted @ 2018-03-15 16:41 喵小喵~ 阅读(203) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 void main() 6 { 7 //&调用外部 8 //function fun = [&]()->void {cout fun = [&](int i) 10 { 11 if (i == 0) 12 { 13 ... 阅读全文
posted @ 2018-03-15 16:16 喵小喵~ 阅读(170) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 void main() 6 { 7 auto fun = [](char *str)->int 8 { 9 int res = 0; 10 char *p = str; 11 int length = strl... 阅读全文
posted @ 2018-03-15 16:13 喵小喵~ 阅读(311) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 int num; 8 int num2; 9 10 public: 11 myclass(int num) 12 { 13 this->num = 0; 14 this->n... 阅读全文
posted @ 2018-03-15 13:33 喵小喵~ 阅读(167) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 5 template 6 void show(T t) 7 { 8 cout 12 void all(Args...args) 13 { 14 int arr[] = { (show(args),0)... }; 15 //int arr[],约束展开,... 阅读全文
posted @ 2018-03-14 18:05 喵小喵~ 阅读(135) 评论(0) 推荐(0)