03 2018 档案
摘要:1 #include 2 //基本数据类型内存池 3 #include 4 //类类型内存池 5 #include 6 //单例模式 7 #include 8 using namespace std; 9 using namespace boost; 10 11 void main1() 12 { 13 //开辟一段内存,五百个字节 14 poolp1...
阅读全文
摘要:1 //#pragma warning(disable : 4819) 2 3 #include 4 #include // for std::cout 5 #include 6 using namespace boost; 7 8 // 构造路由器网络的图模型 9 template 10 void...
阅读全文
摘要:到某个节点最近距离 最短路径当前节点的父节点 完整代码
阅读全文
摘要:到某个点的最短距离 到终点的最短路径 完整代码
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 //A*寻路算法 8 #include 9 using namespace std; 10 using namespace boost; 11 12 enum { A, B, C, D, E, N }; ...
阅读全文
摘要:1 #include 2 #include 3 //图(矩阵实现) 4 #include 5 #include 6 #include 7 //图(链表实现) 8 #include 9 //求最小生成树 10 #include 11 //prim算法求最小生成树 12 #include 13 //深度优先遍历 14 #include 15 //广度优先遍历 16 ...
阅读全文
摘要:1 #include 2 #include 3 //图(矩阵实现) 4 #include 5 #include 6 #include 7 //图(链表实现) 8 #include 9 //求最小生成树 10 #include 11 //prim算法求最小生成树 12 #include 13 //深度优先遍历 14 #include 15 using namesp...
阅读全文
摘要:1 #include 2 #include 3 //图(矩阵实现) 4 #include 5 #include 6 #include 7 //图(链表实现) 8 #include 9 //求最小生成树 10 #include 11 //prim算法求最小生成树 12 #include 13 using namespace std; 14 using namesp...
阅读全文
摘要:1 #include 2 #include 3 //图(矩阵实现) 4 #include 5 #include 6 #include 7 //图(链表实现) 8 #include 9 //求最小生成树 10 #include 11 using namespace std; 12 using namespace boost; 13 14 //顶点名称 15 enu...
阅读全文
摘要:1 #include <iostream> 2 #include <boost/config.hpp> 3 //图(矩阵实现) 4 #include <boost/graph/adjacency_matrix.hpp> 5 #include <boost\graph\graph_utility.hp
阅读全文
摘要:1 #include 2 #include 3 //图 4 #include 5 #include 6 7 using namespace std; 8 using namespace boost; 9 10 //顶点名称 11 enum { A, B, C, D, E, F }; 12 //顶点个数 13 #define N 6 14 const char *na...
阅读全文
摘要:通过Boost库可以在C++项目中使用正则表达式,配置好环境后链接过程出现”无法打开libboost_regex-vc120-mt-sgd-1_62.lib”的错误. 原因是按照官方生成lib的方法没有生成libboost_regex-vc120-mt-sgd-1_62.lib,需要自己生成这个静态
阅读全文
摘要:ref引用不可以复制的对象 1 void print(std::ostream &os, int i) 2 { 3 os << i << endl; 4 } 5 6 //ref引用不可以复制的对象 7 void main1() 8 { 9 vector<int> myint = { 1,2,3,4,
阅读全文
摘要:包含的头文件 1 #include <iostream> 2 #include <string> 3 #include <boost/array.hpp> 4 //异构的容器 5 #include <boost/any.hpp> 6 #include <vector> 7 #include <typ
阅读全文
摘要:1 #include 2 #include 3 #include 4 //异构的容器 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 using namespace boost; 11 12 void main() 13 { 14 boost::arraymyst...
阅读全文
摘要:客户端 1 #include <iostream> 2 #include<string> 3 #include <boost/asio.hpp> 4 #include <stdlib.h> 5 using namespace std; 6 using namespace boost::asio; 7
阅读全文
摘要:客户端 1 #include <boost/asio.hpp> 2 #include <iostream> 3 #include <stdlib.h> 4 using namespace std; 5 using namespace boost::asio; 6 7 void main() 8 {
阅读全文
摘要:node.h 1 #pragma once 2 //创建模板 3 template <class T> 4 class Node 5 { 6 public: 7 T t;//数据 8 Node *pNext;//指针域 9 }; list.h 1 #pragma once 2 #include "N
阅读全文
摘要:C++ 11中的Lambda表达式用于定义并创建匿名的函数对象,以简化编程工作。Lambda的语法形式如下:[函数对象参数](操作符重载函数参数) mutable或exception声明->返回值类型{ 函数体 } 可以看到,Lambda主要分为五个部分:[函数对象参数]、(操作符重载函数参数)、m
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 using namespace boost; 11 12 13 void print(std::ostream &os,int i)...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 using namespace boost; 11 12 13 //function函数包装器 14 void mainC() 15...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 9 //绑定函数的默认值,继承二进制函数类的所有类容 10 class add :public std::binary_function 11 { 12 13 public: 14 void ...
阅读全文
摘要:myvector.h 1 #pragma once 2 3 //自己写的vector模板库 4 template <class T> 5 class myvector 6 { 7 public: 8 //构造 9 myvector(); 10 //析构 11 ~myvector(); 12 //尾插
阅读全文
摘要:1 #include 2 #include 3 #include//区别 4 using namespace std; 5 6 void main() 7 { 8 boost::array myarray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 9 boost::array::iterator ibegin = myarr...
阅读全文
摘要:一、前言 好好研究下大名鼎鼎的Boost库。 二、Boost安装 2.1 Boost官网下载Boost最新版Version 1.55.0 2.2将下载压缩包解压到本地 解压后可看到目录下有个bootstrap.bat文件。 2.3打开cmd命令窗体,执行bootstra.bat文件 运行下面命令,详
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void test() 8 { 9 shared_ptr P(new int[10]{ 1,2,3,4,5,6,7,8,9,0 }); 10 shared_ptr P1 = P; 11 ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 //独享内存,其他指针不可以拥有 8 void test1() 9 { 10 //检测到没有调用的话就不分配内存 11 unique_ptr p(new int[10]{ 0 }); 12 //避免指针被...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct my 8 { 9 int x; 10 int y; 11 }; 12 13 //智能指针主要用于解决内存泄漏,拥有常规指针一样的使用,重载* ->运算符 14 void run1() 15 { 1...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 class myit 5 { 6 public: 7 static int num; 8 9 class itit 10 { 11 12 }; 13 }; 14 15 int myit::num = 0; 16 17 template 18 class my...
阅读全文
摘要:如果容器中是类,如果要调用sort则需要重载操作符 "<" 包含头文件 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <vector> 3 #include <list> 4 #include <algorithm> 5 #include <iostrea
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 //拷贝数据,与反向拷贝 10 { 11 vector myint{ 1,2,3,4,5 }; 12 list myli...
阅读全文
摘要:#include <algorithm> 算法 常用版本 描述 返回Type std::find() find(_InIt _Fisrt,_InIt _Last, _Ty& _Val); 从两个迭代器指定的范围中查找指定值 引用被查找的值的iterator或end() std::find_if()
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 vector myint{ 1,2,3,4,5 }; 10 list mylist{ 10,9,7,6,5 }; 11 //copy不能自动拓展,需要被拷贝的有足够的...
阅读全文
摘要:对容器进行填充 1 void show(int x) 2 { 3 cout << x << endl; 4 } 1 int a[10]; 2 //指定一个数据开始,对a进行填充 3 iota(a, a + 10, 1); 4 5 for_each(a, a + 10, show); 容器两个元素进行
阅读全文
摘要:通过仿函数for_each操作 1 vector<int> myv{ 1,2,3,4,5 }; 2 list<double> db{ 1.1,2.2,3.3,4.4,5.5 }; 3 4 //循环算法,算法的泛型 5 print p = for_each(db.begin(), db.end(),
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 11 //流迭代器 12 void main1() 13 { 14 //vector v{ 1,2...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 void main() 8 { 9 unordered_multiset myset{ "pig", "pig", "pig" ,"chicken"}; 10 /*for (auto i : myset) 11 { 12 ...
阅读全文
摘要:1 #include 2 //老版本的unordered_map(已经废弃不再使用) 3 #include 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 //允许重复的映射 11 hash_mapmymap{ { "a1",113 },{ "a2",143 },{ "a3",112...
阅读全文
摘要:1 #include 2 #include 3 //用于计算,计算的性能高于vector与array 4 #include 5 #include 6 using namespace std; 7 8 9 void main() 10 { 11 const double PI = 3.1415926; 12 valarray val(9); 13 ...
阅读全文
摘要:1 #include 2 #include 3 //查询性能最高 4 //允许重复的,hash_map 5 #include 6 #include 7 using namespace std; 8 9 10 void main() 11 { 12 //允许重复的映射 13 unordered_multimapmymap{ {"a1",113},{ "...
阅读全文
摘要:1 #include 2 #include 3 //查询性能最高 4 //增删查改与map是一样的,但是本质区别就是unordered_map底层是hash表,map底层是红黑树 5 #include 6 using namespace std; 7 8 9 void main() 10 { 11 unordered_mapmymap{ {"a1",113},...
阅读全文
摘要:1 #include 2 #include 3 //查询性能最高(不允许重复数据) 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 unordered_set myset{"move","jump","hello"}; 11 12 //删除hash表第一个 13 //my...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 void main() 8 { 9 multimapmymap; 10 mymap.insert(pair("司令1", 10)); 11 mymap.insert(pair("司令1", 11)); 12 mym...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 //map常规用法 7 void main1() 8 { 9 //映射 10 map mymap; 11 mymap.insert(pair("司令6", 16)); 12 mymap.insert(pair("司令2"...
阅读全文
摘要:1 #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 //hash_set常规用法 10 void main() 11 { 12 ////哈希表不...
阅读全文
摘要:1 #include 2 //红黑树(自动保证平衡,自动生成平衡查找树) 3 #include 4 #include 5 #include 6 using namespace std; 7 8 9 void main() 10 { 11 //红黑树,每一个结点都是一个链表的头结点 12 multiset myset{ 1,2,3,3,3,3,4 };...
阅读全文
摘要:1 #include 2 //红黑树(自动保证平衡,自动生成平衡查找树) 3 #include 4 #include 5 #include 6 using namespace std; 7 8 //红黑树增删查改 9 void main1() 10 { 11 set myset{ 1,2,10,3,5 }; 12 myset.insert(14); 1...
阅读全文
摘要:1 #include 2 //string的本质也是容器 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 string str1 = "1234"; 10 string str2 = "345"; 11 string str3 = str1 + str2; 12...
阅读全文
摘要:1 #include 2 //位运算,处理二进制非常方便,线性存储 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 //bitset mybit(255);//1111 1111 10 //for (int i = 7; i >= 0; i--) 11 //{ ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 8 void main1() 9 { 10 //优先队列 11 priority_queue myq; 12 myq.push(1); 13 myq.push(2); 14 myq.pu...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 10 void main() 11 { 12 //默认deque 13 queue myq; 14 //默认链式队列 15 queue> myli...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 9 void main() 10 { 11 //声明栈,默认是deque(因为删除插入效率比较高) 12 stack mystack; 13 //声明链式栈 14 sta...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 //序列容器的模板类,可对线性排列中指定类型的元素进行排序,并且和矢量一样, 6 //也允许快速随机访问任何元素和在容器后面高效插入和删除。 7 //deque(双端队列),内存实体是分块数据类型,在堆上(优秀与vector与list) 8 //能快速地增删查...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 //array是栈上的数组,自动回收,不能增删查改 7 8 9 //算法迭代函数 10 void change(int &x) 11 { 12 x += 1; 13 } 14 15 void main() 16 { 17 arra...
阅读全文
摘要:1 #include 2 //用于字符串的输入输出 3 #include 4 #include 5 #include 6 //用于输出到字符串 7 #include 8 using namespace std; 9 10 void main1() 11 { 12 //创建字符串流(sprintf) 13 stringstream my...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 //get 三个参数版本(读取一个,读取指定长度,读取到指定字符终止) 8 //getline 2个版本 9 //lcin.ignore(numeric_limits::max(),'#'); 忽略指定字符前的元素 10 //c...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 10 /*char ch1, ch2, ch3; 11 cin.get(ch1).get(ch2).get(ch3); 12 cout.put(ch1).put(ch...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 void main() 6 { 7 ////调用cout的成员函数输出到屏幕 8 //cout.put('a').put('b').put('c'); 9 //char str[100] = "hello world"; 10 //// ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //静态函数没有this指针,无需创建对象就可以直接调用 5 6 template 7 class myclass 8 { 9 public: 10 void go1() 11 { 12 13 } 14 static void go2() 15 { 16 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //static成员,每个类型都会实例化,创建一个变量,类型一致则共享,否则不共享 5 6 template 7 class myclass 8 { 9 public: 10 static int num; 11 myclass() 12 { 13 num...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //模板类的声明,可以引用友元类,也可以创建引用或者指针,不能创建全局对象 5 templateclass showit; 6 7 //错误 8 //showit myint; 9 10 //模板类 11 template 12 class myclass 13 { 14 public: 15...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 template 8 class men 9 { 10 public: 11 men() 12 { 13 14 } 15 ~men() 16 { 17 18 } 19 2...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //嵌套类模板 5 template 6 class myT 7 { 8 public: 9 template 10 class ziT 11 { 12 public: 13 T a; 14 void seta(T t) 15 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //类模板不调用不编译 5 template 6 class myclass 7 { 8 public: 9 T a; 10 T b; 11 T add() 12 { 13 return a + b; 14 } 15 }; 16 17 voi...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //函数包装器,左边参数右边函数 6 template 7 T run(T t, F f) 8 { 9 return f(t); 10 } 11 12 //先获取类型再执行操作 13 template 14 T runit(T t) 15 { 16 //获取...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 template 7 class myarray 8 { 9 private: 10 T * p; 11 public: 12 myarray(initializer_list mylist) 13 { 14 ...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //类模板支撑封装 继承 还有多态 6 template 7 class Tfu 8 { 9 public: 10 T t; 11 Tfu():t(0) 12 { 13 14 } 15 void show() 16 { 17 ...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //模板不能用virtual 6 //函数模板与类成员可以互相调用 7 8 class myclass 9 { 10 template 11 T add(T a) 12 { 13 return a; 14 } 15 t...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 //函数模板,不调用不编译 8 template 9 T add(T a, T b) 10 { 11 return a + b; 12 } 13 14 template ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //子类同名函数覆盖父类 5 //父类指针存储子类地址,在有虚函数情况会调用子类方法,否则会调用父类方法 6 7 class base 8 { 9 public: 10 virtual void show() 11 { 12 cout show(); 29 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //多态调用依赖指针或者引用 5 //对象调用会调用拷贝构造,拷贝一个父类,无法实现多态 6 //如果要使用别继承的虚函数,不允许出现虚函数的重载 7 //多态可以跨类,爷爷辈的指针可以存储孙子辈的地址 8 9 class myclass 10 { 11 public: 12 virtua...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 //后面加一个final,则禁止虚函数被子类重写 8 //final必须对应虚函数 9 virtual void run() final 10 { 11 12 } 13 14 virtua...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 virtual void go() 8 { 9 cout go(); 56 birdpeople aa; 57 cin.get(); 58 }
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //构造函数不可以是虚函数,如果是虚函数子类对象中的父类拷贝无法初始化 5 //继承的本质就是子类中间包含父类对象 6 //析构是从子类析构然后父类析构,如果是多态并且子类中有分配内存, 7 //父类对象用子类初始化,则需要把析构函数设成virtual 8 9 class myclass 10 {...
阅读全文
摘要:1 //#include 2 //using namespace std; 3 // 4 // 5 //void main() 6 //{ 7 // cin.get(); 8 //} 9 10 #define _CRT_SECURE_NO_WARNINGS 11 #include 12 using namespace std; 13 14 class father...
阅读全文
摘要:1 #include "mainwindow.h" 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 //异构数据结构,每个数组元素都是基类指针 11 //异构链表,每一个结点都是基类的指针,指向了派生类 12 //基类指针基...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 class Aobject 5 { 6 public: 7 //虚函数提供一个接口,自动选择子类的接口 8 //存储某个对象的地址,调用对应的方法 9 virtual void show() 10 { 11 cout show(); 29 ci...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 class myclass 5 { 6 public: 7 int i = 10; 8 void show() 9 { 10 cout show(); 30 p2->show(); 31 cin.get(); 32 }
阅读全文
摘要:为什么要用虚基类 虚继承以及虚基类 1 #include <iostream> 2 using namespace std; 3 4 //虚基类 5 class A 6 { 7 public: 8 int a; 9 public: 10 A() 11 { 12 cout << "A()" << en
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //构造的时候,从父类到子类构造 5 //子类构造先调用父类构造 6 class myclass 7 { 8 public: 9 int x; 10 int y; 11 12 public: 13 myclass(int a,int b):x(a),y(b) 14 ...
阅读全文
摘要:1 #include 2 #include "coder.h" 3 #include "cppcoder.h" 4 #include "cocoscoder.h" 5 using namespace std; 6 7 void test() 8 { 9 cocoscoder man; 10 } 11 12 //继承,父类不依赖于子类,子类依赖于父类 13 //构造...
阅读全文
摘要:三种访问权限 public:可以被任意实体访问 protected:只允许子类及本类的成员函数访问 private:只允许本类的成员函数访问 三种继承特点 1、public继承不改变基类成员的访问权限 2、private继承使得基类所有成员在子类中的访问权限变为private (基类的private
阅读全文
摘要:1 #include "mainwindow.h" 2 #include 3 #include > 4 5 //重载的三种形式,成员函数重载 6 //友元函数重载,可以使用私有变量以及保护变量 7 //一般函数重载都是公有变量 8 9 class buttons 10 { 11 QPushButton *p; 12 int n; 13 14 public...
阅读全文
摘要: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...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 using namespace std; 5 6 //返回值为类的引用不会调用拷贝构造 7 //拷贝构造要深拷贝,赋值重载(=)也要深拷贝 8 //注意对象如果是在栈上,有生命周期,拷贝栈上的对象需要深拷贝 9 10 class mystring 11 {...
阅读全文
摘要:非指针,则深浅拷贝都一样,含有指针则内存共享,指针一致,内容一直 深拷贝,指针不一致,内存一直,内存是独享的 赋值重载如果有返回自身类型对象,会调用拷贝构造,需要重载拷贝构造,这一点是必须要注意的,原理是:先操作一个类,再把操作的这个类拷贝到本类中,即使返回(*this),也会调用 (如果返回值是自
阅读全文
摘要:shortsafe operator ++() 先自增再引用 shortsafe operator ++(int) 先引用再自增后面,需要副本(先用副本进行操作,然后再进行自己类的++改变数据)(返回的都是修改后的数据) ()可以把对象名当做括号来操作 代码示例
阅读全文
摘要: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), ...
阅读全文
摘要: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 { ...
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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 ...
阅读全文
摘要:静态函数没有this指针,无法调用成员变量与成员函数 没有对象名也可以访问,也可以通过对象名访问 静态成员函数经常与静态成员数据配合使用 代码示例
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 class myclass 6 { 7 public: 8 //static只会初始化一次 9 static int num; 10 myclass() 11 { 12 num += 1; 13 } 14 ~my...
阅读全文
摘要:类中可以包含引用成员,但必须在定义变量的时候默认初始化 引用作用域参数和返回值,避免内存占用 常引用等价于常对象 常引用等价于常对象 完整代码
阅读全文
摘要: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 ...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 using namespace std; 5 6 //默认拷贝构造只是值传递,对于数据有效,对于指针则是同一个指向,需要重写一下拷贝构造 7 //类的内部有指针分配内存,需要深拷贝,否则需要浅拷贝 8 class mystring 9 { 10 public...
阅读全文
摘要: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...
阅读全文
摘要:const常量对象,无法改变数据,只能引用尾部带const方法 类的成员如果是const,可以默认初始化,也可以构造的初始化,不可在构造函数内部初始化 类中的const成员,无法直接修改,可以间接修改 类的成员函数const三种情形:1.返回值const,2.返回常量,3.参数const,可读不可写
阅读全文
摘要: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]...
阅读全文
摘要: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...
阅读全文
摘要:设置断点调试 在一行代码的左侧点击即可设置断点,按F5(调试->开始调试)即可运行到第一个端点处暂停 逐语句调试 按F11(调试->逐语句)即可开始一步一步执行 逐过程调试 按F10(调试->逐过程)开始逐过程调试,此方法不会进入调用的函数里面 原文此处的 Step into a property
阅读全文
摘要: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 ...
阅读全文
摘要:面向过程: 创建一个类继承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 {
阅读全文
摘要: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 ...
阅读全文
摘要:1 #include 2 #include //类型索引 3 #include //红黑树 4 #include 5 using namespace std; 6 7 class myclass 8 { 9 10 }; 11 12 void main() 13 { 14 //索引与string进行映射 15 unordered_map mytype;/...
阅读全文
摘要: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...
阅读全文
摘要:按钮点击获取文本框输入 1 void Dialog::on_pushButton_clicked() 2 { 3 //获取文本输入 4 QString vstr = ui->lineEdit->text(); 5 6 //判断是否转换成功 7 bool isok; 8 //转换 9 int valu
阅读全文
摘要:一维数组封装 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
阅读全文
摘要: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...
阅读全文
摘要: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 //...
阅读全文
摘要: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(...
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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[],约束展开,...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //拷贝构造,构造,析构,赋值重载 5 //C++会给每个类生成四个函数,写了新函数会覆盖 6 class myclass 7 { 8 public: 9 //不允许拷贝构造 10 myclass(const myclass &my) = delete; 11 //mycla...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 class myclass 8 { 9 public: 10 myclass() 11 { 12 cout my;//分配器 28 myclass *p = my.allocate(1)...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 using namespace std::placeholders; 8 9 class myclass 10 { 11 public: 12 int get(int data) 13 { 1...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 void main() 6 { 7 cout ::max() ::min() << endl; 9 cin.get(); 10 }
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //异常与错误不一样,异常一般能正常工作 5 //错误就是程序无法正常工作,无法编译 6 //异常让程序在错误的输入,文件不存在,内存异常仍然可以正常工作 7 8 int divv(int a, int b) 9 { 10 try 11 { 12 if (b == ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 //vector g_all; 10 //创建list存放数据 11 list g_all; 12 13 //统计共有多少数据 14 int i = 0; 15 16 /...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 void main() 10 { 11 ifstream fin("F:\\大数据\\大数据相关数据\\kaifang.txt"); 12 ofstream fou...
阅读全文
摘要:前提是要包含头文件 判断是否是左值引用 是否是右值引用 是否是数组 是否是一个整数 是否是一个类 1 check(1, 10); 2 int i(10); 3 int &ri(i); 4 int &&rri(i + 3); 5 //判断是否是左值引用 0不是 1是 6 cout << is_lval
阅读全文
摘要:regex_match 整个字符串是否匹配 (通过cmatch存储匹配的结果),match[0]代表整个匹配序列,match[1]代表第1个匹配后的子序列,match[2]代表第2个匹配后的子序列 代码示例: regex_search 整个字符串进行查找判断是否含有指定数据类型 regex_repl
阅读全文
摘要:正则表达式是什么? 字符是计算机软件处理文字最基本的单位,可以是字母,也可以是数字,标点符号,空格,换行符,汉字等等. 字符串是0个或更多个字符的序列.文本也就是文字,字符串.说某个字符串匹配某个正则表达式,通常是指这个字符串里有一部分(或几部分分别)能满足表达式给出的条件. 我们在处理字符串的程序
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 8 void main() 9 { 10 //string str("\"C:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQScLauncher.exe\""); 11 //\n不会换行,...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 using namespace std::placeholders; 5 6 int add(int a, int b) 7 { 8 return a + b; 9 } 10 11 class myclass 12 { 13 public: 14 int ope...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //模板自动匹配*多的 5 template 6 void com(T *p) 7 { 8 cout 13 void com(T **p) 14 { 15 cout << "**" << endl; 16 cout << typeid(T).name() << endl; ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //模板可以设置有默认值 5 template 6 void hello(T str) 7 { 8 cout 14 void show(T1 t1 = 1, T2 t2 = 2, T3 t3 = 3) 15 { 16 cout ("hello"); 24 show(); 2...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 using namespace std::placeholders; 5 6 class myclass 7 { 8 public: 9 void add1(int a) 10 { 11 cout << a << endl; 12 } 13...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 void go(T t1) 6 { 7 cout 11 void go(T *t1) 12 { 13 cout << "******" << endl; 14 } 15 16 void main() 17 { 18 int *p = new int[2]...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //ref 在模板中变量转化为引用 5 //move 左值引用转化为右值引用 6 //副本,不能改变数据 7 template 8 void print1(T t) 9 { 10 t += 1; 11 cout 15 void print2(T &t) 16 { 17 t...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 //传递模板进去自动确定模板的元素类型 7 template 8 void showall(vector v,list l) 9 { 10 for (auto i : v) 11 { 12 cout myint{ 1,...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 using std::function; 5 6 int add(int a, int b) 7 { 8 return a + b; 9 } 10 11 template 12 T run(T t1, T t2, F f) 13 { 14 return f(t...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 void show(T t) 6 { 7 cout << t << endl; 8 t += 10; 9 } 10 11 void main() 12 { 13 double db(1.0); 14 double &ldb(db); 15 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 class myclass 6 { 7 public: 8 T t; 9 void show(T tx) 10 { 11 cout t1; 29 30 //检测某个模板有没有根据某个类型实例化 31 __if_exis...
阅读全文
摘要:初始化单向链表 1 forward_list<int> list1{ 1,2,3,4,5 }; 链表排序 1 list1.sort();//排序 前插 1 list1.push_front(10); 链表反转 1 list1.reverse(); 链表头结点 1 auto ib = list1.be
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //显示{}中的数据 6 void show(initializer_list list) 7 { 8 for (auto i : list) 9 { 10 cout list) 16 { 17 int length = list.s...
阅读全文
摘要:数据类型转换(static_cast) //数据类型转换 printf("%d\n", static_cast<int>(10.2)); 指针类型转换(reinterpret_cast) 1 指针类型转换 2 int *pint = new int(1); 3 char *pch = reinter
阅读全文
摘要:要想解决死锁就需要lock与unlock成对使用,不允许连续使用两个lock
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 //通过mutex 等待事件响应 10 condition_variable isfull, isempty;//处理两种情况 11 mutex m; 12 bool flag =...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 condition_variable cv; 11 mutex m; 12 bool done = false; 13 14 void run() 15...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 #define N 100000 7 8 mutex g_mutex; 9 10 void add(int *p) 11 { 12 for (int i = 0; i lgd(g_mutex); 16 //unique也能...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //交换线程,线程移动 6 void main() 7 { 8 thread t1([]() {cout << "hello" << endl; }); 9 thread t2([]() {cout << "hello3" << endl; }); 10 ...
阅读全文
摘要:1 //编写一个 程序,开启3个线程,这3个线程的ID分别为A,B,C 2 //每个线程将自己的ID在屏幕打印10遍 3 //要求输出结果必须按ABC的顺序显示 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 int LOOP = 10; 11 int flag = 0; ...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 #define COUNT 1000000 10 11 //创建互斥量 12 mutex m; 13 14 //多...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int go(const char *fmt, ...) 9 { 10 va_list ap;//指针 11 va_start(ap, fmt)...
阅读全文
摘要:创建vector数组 1 vector<int> myint{ 1,2,3,4,5 }; 尾部插入 1 for (int i = 10; i < 20; i++) 2 { 3 myint.push_back(i); 4 5 } 读取头部和尾部 1 cout << myint.front() << e
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include //线程将来的结果 5 #include 6 #include 7 using namespace std; 8 9 mutex g_m; 10 11 12 void main() 13 { 14 auto run = [...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 //线程通信,结合mutex 9 //一个线程,多个线程处于等待,通知一个或者通知多个 10 11 mutex m;//线程相互排斥 12 conditio...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 promise val;//全局通信变量 10 void main() 11 { 12 //字符串相加 13 /*st...
阅读全文
摘要:1 #define _CRT_SECURE_NO_WARNINGS 2 #include 3 #include 4 #include 5 using namespace std; 6 7 class fun 8 { 9 public: 10 char str[100]; 11 public: 12 fun(char *str) 13 { 14 ...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //伪函数,可以将对象名当做函数来使用 6 struct func 7 { 8 func() 9 { 10 cout << "create "<< endl; 11 } 12 ~func() 13 { 14 ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 //声明类 7 class myclass; 8 9 struct info 10 { 11 myclass *p;//指针,内存首地址 12 int n;//代表有多少个对象 13 }; 14 15 ...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //全局内存管理,统计释放内存,分配内存 6 7 //重载全局的new 8 void *operator new(size_t size) 9 { 10 cout << "g_new call" << endl; 11 void *p = malloc(si...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 //获取线程id 11 thread th1([]() { 12 //等待 13 this_thread::sleep_for(chro...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 //全局变量会造成冲突,使得结果不正确 8 //mutex结果正确,速度慢 9 //atomic 结果正确,速度快 10 11 12 //线程安全,多线程访问不冲突 13 //int num = 0; 14 15 //原子...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void show() 8 { 9 MessageBoxA(0, "1", "1", 0); 10 } 11 12 void main() 13 { 14 //获取CPU核心的个数 15 auto n ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 void run() 7 { 8 MessageBoxA(0, "0", "0", 0); 9 } 10 11 void showmsg(const char *str1,const char *str2) 12 { 13 Messa...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 struct info 6 { 7 int id; 8 int num; 9 //堆上面开辟内存必须有构造函数 10 info(int nid, int nnum) :id(nid), num(nnum)//构造函数 11 { 12 ...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //指行system指令 6 void gocmd(const char *cmd) 7 { 8 system(cmd); 9 } 10 11 //输出cmd指令 12 void showcmd(const char *cmd) 13 { 14 cout <...
阅读全文
摘要:引用的本质就是两个变量名的地址是同一块内存,可以改变该地址指向的内容 引用指针可以改变指针指向的地址(因为取地址就是指针变量的地址,地址改变,原指针指向的地址也变了),也可以改变指针指向的内容 左值引用与右值引用 1 //左值引用与右值引用 2 void main1() 3 { 4 int a(4)
阅读全文
摘要:1 #include 2 using namespace std; 3 //改变指针,需要二级指针,也可以用引用 4 5 //左值引用与右值引用 6 void main1() 7 { 8 int a(4); 9 int *p(new int(5)); 10 cout << a << endl; 11 cout << *p << endl; 1...
阅读全文
摘要:左值引用主要用于引用内存 右值引用主要用于引用寄存器 代码示例
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 6 void main() 7 { 8 char ch = 'a'; 9 short sh = 12; 10 int num = 234; 11 double db = 12.324; 12 char *p = "calc"; 13 ...
阅读全文
摘要:#include #include #include using namespace std; //老版本智能指针 void autoptr() { while (1) { double *p( new double[1024 * 1024 * 10] ); auto_ptrautop(p);//接管,自动回收 Sleep(...
阅读全文
摘要:1 //模板元实现递归加速,编译的时候慢,代码会增加 2 //把运行的时间节约在编译的时候 3 //递归加速,游戏优化 4 #include 5 using namespace std; 6 7 template 8 struct mydata 9 { 10 enum{res=mydata::res+mydata::res}; 11 }; 12 13 templa...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 using std::function;//函数包装 5 6 void go() 7 { 8 cout fun1 = go; 19 fun1(); 20 //用lambda表达式包装 21 function fun2 = []() {cout f...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //解决函数怀孕现象 6 //[](){} 7 //[] =引用,只读 =mutable读原本改副本 &读写原本 //&a,b a可读写,b只能读 8 //() 参数,int a,int b 9 //{}语句 10 void main() 11 { 12 //lamb...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 5 6 7 8 namespace all 9 { 10 //inline作用为默认调用 11 inline namespace V2017 12 { 13 void fun(int num) 14 { 15 c...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //声明返回值为常量表达式 5 constexpr int get() 6 { 7 int num = 5; 8 return num; 9 } 10 11 void main() 12 { 13 int a[5 + get()]; 14 cin.get(); 15...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //定义返回值类型 6 template 7 auto add(T1 t1, T2 t2)->decltype(t1 + t2) 8 { 9 return t1 + t2; 10 } 11 12 //模板别名,用别名优化模板的名称,只能放在类,命名空间,全局,不能...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 5 void main() 6 { 7 int a; 8 cout << typeid(a).name() << endl; 9 cin.get(); 10 }
阅读全文
摘要:另一个文件声明 #include <iostream> using namespace std; int x = 10; void show() { cout << "1234" << endl; } 本文件使用 1 #include <iostream> 2 using namespace std
阅读全文
摘要:1 #include 2 using namespace std; 3 4 //扩展标准命名空间 5 //数据类型可以放在命名空间,避免冲突 6 namespace std 7 { 8 //拥有class所有功能 9 struct data 10 { 11 int a; 12 int b; 13 //声...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 //CPP没有声明和定义的差别,只有定义 6 int a; 7 //int a; 8 9 //一般禁止使用匿名命名空间,等同于全局作用域 10 namespace 11 { 12 int a = 10; 13 } 14 15 //定义全局变量 16 int num...
阅读全文
摘要:1 #include 2 #include 3 using namespace std; 4 5 void show(int num) 6 { 7 cout << "int" << endl; 8 } 9 10 void show(int *p) 11 { 12 cout << "int *" << endl; 13 } 14 15 void main...
阅读全文
摘要:C++风格数组 1 #include <iostream> 2 #include <array> 3 using namespace std; 4 5 6 7 void main() 8 { 9 //一维数组 10 //在栈上分配内存 11 //前面是元素类型 12 array<int, 10>my
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 void show(T *p) 6 { 7 //初始化 8 decltype(*p) num(*p); 9 cout << *p << endl; 10 } 11 12 void main() 13 { 14 auto man("2134")...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 auto add(T1 t1, T2 t2) 6 { 7 return t1 + t2; 8 } 9 10 //auto自适应数据类型,自动推理 11 void main() 12 { 13 auto num = 10; 14 cout << typ...
阅读全文
摘要://默认参数要指定放在右边 1 #include 2 #include 3 using namespace std; 4 5 int add(int a,int b,int c = 1) 6 { 7 return a + b + c; 8 } 9 10 void main() 11 { 12 cout << add(1, 2); 13 14 }
阅读全文
摘要:参数不一致实现printf 1 #include <iostream> 2 #include <cstdarg> 3 using namespace std; 4 5 //递归终止 6 void show(const char *str) 7 { 8 } 9 10 template<typename
阅读全文
摘要:namespace用法示例 1 #include <iostream> 2 using namespace std; 3 4 //定义域名空间 5 namespace myspace 6 { 7 int num = 45; 8 void show() 9 { 10 cout << num << en
阅读全文
摘要:VISITOR 访问者模式 访问者模式:访问者模式的目的是封装一些施加于某种数据结构元素之上的操作。一旦这些操作需要修改的话,接受这个操作的数据结构可以保持不变。访问者模式适用于数据结构相对未定的系统,它把数据结构和作用于结构上的操作之间的耦合解脱开,使得操作集合可以相对自由的演化。访问者模式使得增
阅读全文
摘要:OBSERVER 观察者模式 观察者模式:观察者模式定义了一种一队多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态上发生变化时,会通知所有观察者对象,使他们能够自动更新自己。 想知道咱们公司最新MM情报吗?加入公司的MM情报邮件组就行了,tom负责搜集情报,他发现的新情报不用
阅读全文
摘要:ADAPTER 适配器模式 适配器(变压器)模式:把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口原因不匹配而无法一起工作的两个类能够一起工作。适配类可以根据参数返还一个合适的实例给客户端。 在朋友聚会上碰到了一个美女Sarah,从香港来的,可我不会说粤语,她不会说普通话,只好求助于我
阅读全文
摘要:TEMPLATE METHOD 模板模式 模板方法模式:模板方法模式准备一个抽象类,将部分逻辑以具体方法以及具体构造子的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑。不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的逻辑有不同的实现。先制定一个顶级逻辑框架,而将逻辑的细节留给具体的子
阅读全文
摘要:STRATEGY 策略模式 策略模式:策略模式针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。策略模式使得算法可以在不影响到客户端的情况下发生变化。策略模把行为和环境分开。环境类负责维持和查询行为类,各种算法在具体的策略类中提供。由于算法和环境独立开来,算法的增减
阅读全文
摘要:建造模式:将产品的内部表象和产品的生成过程分割开来,从而使一个建造过程生成具有不同的内部表象的产品对象。建造模式使得产品内部表象可以独立的变化,客户不必知道产品内部组成的细节。建造模式可以强制实行一种分步骤进行的建造过程。 MM最爱听的就是“我爱你”这句话了,见到不同地方的MM,要能够用她们的方言跟
阅读全文
摘要:1 #include 2 3 //处理消息的回调函数 4 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 5 6 int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hpreinstance, PSTR szcmdline, int icmdshow) 7 { 8 ...
阅读全文
摘要:1 #include 2 #include 3 4 #define LEN 4 //标识从所有数据中选出几个 5 6 //保存结果 7 char res[LEN+1] = { 0 }; 8 //保存有多少个 9 int count = 0; 10 11 //全排列(有重复) 12 //j为当前位置 13 void showall(char *p , int j) 14...
阅读全文

浙公网安备 33010602011771号