上一页 1 ··· 33 34 35 36 37 38 39 40 41 ··· 68 下一页
摘要: 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) 编辑
摘要: 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 //声... 阅读全文
posted @ 2018-03-11 12:05 喵小喵~ 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 12:00 喵小喵~ 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 11:52 喵小喵~ 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2018-03-11 11:43 喵小喵~ 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 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")... 阅读全文
posted @ 2018-03-11 11:35 喵小喵~ 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-03-11 11:24 喵小喵~ 阅读(125) 评论(0) 推荐(0) 编辑
摘要: //默认参数要指定放在右边 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 } 阅读全文
posted @ 2018-03-11 11:06 喵小喵~ 阅读(126) 评论(0) 推荐(0) 编辑
上一页 1 ··· 33 34 35 36 37 38 39 40 41 ··· 68 下一页