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

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

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

auto

自动化变量

auto a = 12;
auto b = 12.0f;
auto c = true;
auto d = [] (int x)->int{ return 12;};
auto e = std::bind(&func, _1);

延迟绑定

template<typename T, typename L>
auto fun(T x, L y)->decltype(x + y){return x;}

using

定义别名

template<typename T>
using Tlist = std::list<T>;
using Tlist = std::list<char>;
using df = void(*)();//等价于typedef void(*df)()


 
 
和typedef的区别:
  • 定义一般类型的别名没区别。
C++11标准7.1.3.2:( isocpp.org/files/papers )
2 A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It has the same semantics as if it were introduced by the typedef specifier. In particular, it does not define a new type and it shall not appear in the type-id. [Example: using handler_t = void (*)(int); extern handler_t ignore; extern void (*ignore)(int); // redeclare ignore using cell = pair<void*, cell*>; // ill-formed — end example ]
  • 定义模板的别名,只能使用using

使用外部构造

using A::A;

引入外部类型

using typename A; 

extern

外部模板

extern template<typename T>void(T t);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值