码迷,mamicode.com
首页 > 编程语言 > 详细

C++11老关键字的新含义(auto, using,extern)

时间:2016-05-21 20:15:15      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.csdn.net/cnsword/article/details/8034947

公司可以使用c++11.看大牛的代码模仿使用,所以现在已经不知道什么使用的是c++的语法还是c++11的语法了...不知道算不算是一种悲哀

 

C++11对关键字进行了修订,加入了nullptr、constexpr、decltype、default、static_assert等,同时原有的关键字(auto,using,extern)含义和用途进行了修订。在这里主要了解一下对auto、using、extern这三个关键字的修订。

auto : 

 1 /*自动化变量*/
 2 auto a = 12;
 3 auto b = 12.0f;
 4 auto c = "abc"
 5 auto d = [] (int x)->int{return 12;} //参见c++文章<c++lambda表达式>
 6 auto e = std::bind(&func, _1);//参见c++文章<std::function和std::bind函数指针>
 7 
 8 vector<int> s;
 9 s.push_back(1);
10 s.push_back(2);
11 for (auto it = s.begin(); it != s.end(); it++)
12 {
13     cout<<*it<<endl;
14 }
15 
16 /*延迟绑定*/   //参见文章 <c++11的decltype>
17 template<typename T, typename L>
18 auto fun( T x, L y)->decltype(x + y){return x;}

using : 

 1 /*定义别名*/
 2 template<class T>
 3 using Tlist = std::list<T>;
 4 
 5 using Tlist = std::list<char>;
 6 Tlist listChar;
 7 
 8 //typedef void (*df)()
 9 using  df = void(*)();
10 
11 /*使用外部构造*/
12 using A::A;
13 
14 /*引用外部类型*/
15 using typename A;

extern

 1 /*外部模板*/

2 extern template<class T>void(T t);

 

C++11老关键字的新含义(auto, using,extern)

标签:

原文地址:http://www.cnblogs.com/silentNight/p/5508061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!