摘要: 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... 阅读全文
posted @ 2018-03-11 23:01 喵小喵~ 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 21:40 喵小喵~ 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 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 //原子... 阅读全文
posted @ 2018-03-11 21:33 喵小喵~ 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2018-03-11 21:22 喵小喵~ 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 21:11 喵小喵~ 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2018-03-11 21:01 喵小喵~ 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 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 <... 阅读全文
posted @ 2018-03-11 20:42 喵小喵~ 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 引用的本质就是两个变量名的地址是同一块内存,可以改变该地址指向的内容 引用指针可以改变指针指向的地址(因为取地址就是指针变量的地址,地址改变,原指针指向的地址也变了),也可以改变指针指向的内容 左值引用与右值引用 1 //左值引用与右值引用 2 void main1() 3 { 4 int a(4) 阅读全文
posted @ 2018-03-11 17:27 喵小喵~ 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 16:23 喵小喵~ 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 左值引用主要用于引用内存 右值引用主要用于引用寄存器 代码示例 阅读全文
posted @ 2018-03-11 15:46 喵小喵~ 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2018-03-11 15:24 喵小喵~ 阅读(125) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; //老版本智能指针 void autoptr() { while (1) { double *p( new double[1024 * 1024 * 10] ); auto_ptrautop(p);//接管,自动回收 Sleep(... 阅读全文
posted @ 2018-03-11 15:18 喵小喵~ 阅读(2028) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 15:02 喵小喵~ 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 14:48 喵小喵~ 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 14:43 喵小喵~ 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 14:04 喵小喵~ 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 13:58 喵小喵~ 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 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 //模板别名,用别名优化模板的名称,只能放在类,命名空间,全局,不能... 阅读全文
posted @ 2018-03-11 13:48 喵小喵~ 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 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 } 阅读全文
posted @ 2018-03-11 12:14 喵小喵~ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 另一个文件声明 #include <iostream> using namespace std; int x = 10; void show() { cout << "1234" << endl; } 本文件使用 1 #include <iostream> 2 using namespace std 阅读全文
posted @ 2018-03-11 12:12 喵小喵~ 阅读(96) 评论(0) 推荐(0) 编辑