首页 > 编程语言 > 详细

C++11标准特性的一些理解

时间:2021-07-10 22:01:06      阅读:29      评论:0      收藏:0      [点我收藏+]

(1)auto关键字和decltype关键字

在C++11之前,auto关键字用来指定存储期。在新标准中,它的功能变为类型推断。C++11引入auto关键词与之前C语言的auto意义已经不一样了。这里的auto是修饰未知变量的类型,编译器会通过此变量的初始化自动推导变量的类型。

例如:auto x = 1;编译器会通过“1”值,推导出变量x是整型。但在C++11之前,采用auto关键字定义变量 i = x,会抛出“declaration with no type”错误,如下:

技术分享图片

 

 更新为C++11标准之后,auto关键字能够声明并定义变量类型(自动推导)

#include<iostream>
#include<typeinfo>
suing namespace std;

int main()
{
    auto i = 1;
    auto j = 1.5;
    auto k = true;
    auto m = c;
    auto n = "abcd";
    cout<<typeid(i).name<<endl;
    cout<<typeid(j).name<<endl;
    cout<<typeid(k).name<<endl;
    cout<<typeid(m).name<<endl;
    cout<<typeid(n).name<<endl;
    
    return 0;
} 

 

如果初始值是引用,如:

(2)defaulted and deleted functions
(3)final and override
(3)trailing return type
(4)rvalue references
(5)move constructors and move assignment operators
(6)scoped enums
(7)constexpr and literal types
(8)list initialization
(9)delegating and inherited constructors
(10)brace-or-equal initializers
(11)nullptr
(12)long long
(13)char16_t and char32_t
(14)type aliases
(15)variadic templates
(16)generalized (non-trivial) unions
(17)generalized PODs (trivial types and standard-layout types)
(18)Unicode string literals
(19)user-defined literals
(20)attributes
(21)lambda expressions
(22)noexcept specifier and noexcept operator
(23)alignof and alignas
(24)multithreaded memory model
(25)thread-local storage
(26)GC interface
(27)range-for (based on a Boost library)
(28)static_assert (based on a Boost library)

C++11标准特性的一些理解

原文:https://www.cnblogs.com/JCpeng/p/14994370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!