using别名

 1 /* using别名 */
 2 
 3 #include<iostream>
 4 
 5 namespace space // 隔离模板 避免冲突
 6 {
 7 
 8     template<class T> using ptr = T*;// 模板简写
 9     
10 }
11 
12 int add(int a,int b)
13 {
14     return a+b;
15 }
16 
17 typedef int (* ADD)(int a,int b)// C 别名
18 using FUNC = int (*)(int a,int b);// c++ 别名
19 
20 using co = std::ios_base::fmtflags;// using 只可以用于简写数据类型
21 
22 int main()
23 {
24     ADD p = add;
25     std::cout << p(1,2) << std::endl;
26     
27     FUNC func = add;
28     std::cout << func(1,2) << std::endl;
29 
30     space::ptr<int> pint(new int(3));//根据一个指针分配内存 并把内存初始化为3
31     std::cout << *pint << " " << pint << std::endl;
32     
33     std::cin.get();
34     return 0;
35 }

 

posted on 2015-06-02 10:45  Dragon-wuxl  阅读(162)  评论(0)    收藏  举报

导航