[c++]c++11 新标准
2015-10-16 16:25
387 查看
1. constexpr
要求编译器去确认变量是常量表达式
当用constexpr修饰指针,说明是指针常量,不是指向常量的指针
2. alias declaration
3. auto
编译器自动根据表达式的结果推测变量类型
auto忽略top-level const, low-level const保留
4. decltype
当我们只想用编译器从表达式中推测出来的类型,而不是用表达式来初始化这个类型(like auto),就用decltype
decltype同时保留了top-level和low-level的const
5.类中初始化器
{}或者= ,()不行。
6. range for statement
for(declaration : expression)
statement;
7. vector 用花括号初始化
vector<string> strs={"erd","sdg","acv"};//再也不用一个一个push_back()啦
花括号不能用()代替
要求编译器去确认变量是常量表达式
constexpr int sz=size(); //编译时除非size()是constexpr function,否则不通过
当用constexpr修饰指针,说明是指针常量,不是指向常量的指针
const int *p=nullptr; //指向常量的指针 constexpr int *q=nullptr;//指针常量
2. alias declaration
using SI=Sales_item;// similar to typedef Sales_item SI;
3. auto
编译器自动根据表达式的结果推测变量类型
auto忽略top-level const, low-level const保留
int a=10; const int * const p=&a; auto pp=p;// pp is const int * 指向常量的指针,top-level const需要在auto前面加上 const const auto pp=p;
4. decltype
当我们只想用编译器从表达式中推测出来的类型,而不是用表达式来初始化这个类型(like auto),就用decltype
decltype(f()) sum=x;
decltype同时保留了top-level和low-level的const
5.类中初始化器
{}或者= ,()不行。
class book{ string isbn; double price{0.0}; int piece=0; };
6. range for statement
for(declaration : expression)
statement;
//example string str("some string"); decltype(str.size()) count=0; for(auto c: str) if(isspace()) count++; //if need to change the element in str using auto & for(auto &c:str) c=toupper(c);
7. vector 用花括号初始化
vector<string> strs={"erd","sdg","acv"};//再也不用一个一个push_back()啦
花括号不能用()代替
相关文章推荐
- 100到200之间的素数输出(初)
- Visual C++ 2010 ATL /CLR/MFC/Win32有何不同
- c++模板与泛型编程基础
- C语言经典面试题
- 【c++ templates读书笔记】【7】模板元编程
- 【c++ templates读书笔记】【7】模板元编程
- C语言程序判断文件夹是否存在
- 谈论C++当然结果
- c语言:统计整数二进制表示中1的个数(汉明重量)
- C++STL学习(5)容器map和multimap
- C++ Struct
- 如何将C++中的SOCKADDR_IN*参数类型转换成C#中的参数类型
- c++ # ## 区别
- C++ MD5加密函数
- vs/vc++中无法解析的外部符号
- C++操作一个Excel字体大小 边框 对齐方式等
- C语言小问题集锦
- 爬爬爬之路:C语言(七) 结构体篇
- C++标准模板库中list大数据量情况下析构效率的研究
- C++primer学习:拷贝控制(1)