摘要: 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; ... 阅读全文
posted @ 2018-03-12 23:55 喵小喵~ 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 23:51 喵小喵~ 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 23:44 喵小喵~ 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 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]... 阅读全文
posted @ 2018-03-12 23:28 喵小喵~ 阅读(84) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 23:24 喵小喵~ 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 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,... 阅读全文
posted @ 2018-03-12 23:14 喵小喵~ 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 23:05 喵小喵~ 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2018-03-12 23:00 喵小喵~ 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 22:20 喵小喵~ 阅读(469) 评论(0) 推荐(0) 编辑
摘要: 初始化单向链表 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 阅读全文
posted @ 2018-03-12 21:13 喵小喵~ 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 20:07 喵小喵~ 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 声明+delete:函数禁止使用.可以使一个类禁止释放 阅读全文
posted @ 2018-03-12 19:58 喵小喵~ 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 数据类型转换(static_cast) //数据类型转换 printf("%d\n", static_cast<int>(10.2)); 指针类型转换(reinterpret_cast) 1 指针类型转换 2 int *pint = new int(1); 3 char *pch = reinter 阅读全文
posted @ 2018-03-12 19:55 喵小喵~ 阅读(6850) 评论(0) 推荐(0) 编辑
摘要: 要想解决死锁就需要lock与unlock成对使用,不允许连续使用两个lock 阅读全文
posted @ 2018-03-12 17:12 喵小喵~ 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 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 =... 阅读全文
posted @ 2018-03-12 16:47 喵小喵~ 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-12 16:08 喵小喵~ 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 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也能... 阅读全文
posted @ 2018-03-12 15:56 喵小喵~ 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2018-03-12 15:49 喵小喵~ 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 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; ... 阅读全文
posted @ 2018-03-12 15:44 喵小喵~ 阅读(187) 评论(0) 推荐(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 //多... 阅读全文
posted @ 2018-03-12 15:23 喵小喵~ 阅读(146) 评论(0) 推荐(0) 编辑