C++11特性
文章平均质量分 74
learn123_net
http://learn123.net There are lots of products in the market that make you dazzled and you dont know how to make a choice. In here we introduce the latest fashion and popular treands. Therefore you learn it first,and then buy the goods that you bes
展开
-
C++11特性--统一的初始化,std::initializer_list
注:本系列笔记所有内容的参考资料来源于《C++ Primer Plus》 C++11特性需编译器支持,如果是WindowS集成开发环境,一般需要在IDE的编译器选项里找或者工程的属性里可以配置"-std=c++11" 以devC++为例:project==>project options==>Parameters==>原创 2013-07-22 11:12:28 · 4772 阅读 · 0 评论 -
C++11特性--auto,decltype,返回类型后置,using=,nullptr
1.auto *C++11将其用于实现自动类型推断(这要求显式初始化,让编译器将变量类型设置为初始值的类型) void fun(int x) { cout } int main() { auto x=1; auto px=&x; auto pf=fun; //等效于void (*pf)(int);pf=fun;原创 2013-07-23 18:05:55 · 1187 阅读 · 0 评论 -
C++11特性--作用域内枚举,显式转换符,类内成员初始化
1.作用域内枚举 C++11新增了一种枚举。这种枚举使用class或struct定义: *新枚举要求进行显式限定,以免发生名称冲突 *作用域枚举不能隐式地转换为整型 Example: enum class animal { sun,cat,dog }; int main() { animal mycat=animal::cat;原创 2013-07-24 00:21:58 · 1115 阅读 · 0 评论 -
C++11特性--基于范围的for循环,新的STL容器,新的STL方法( cbegin(),cend(),crbegin(),crend())
1.模板和STL方面的修改 (1)基于范围的for循环 *对于内置数组以及包含方法begein()和end()的类合和STL容器,基于范围的for循环可简化为它们编写循环的工作 *如果要在循环中修改数组或容器的每个元素,可使用引用类型 Example: int main() { int arr[]{1,2,3}; for(auto x:arr) { cout原创 2013-07-24 18:24:17 · 2655 阅读 · 0 评论 -
C++11特性--右值引用,移动语义,强制移动move()
1.右值引用 *右值:不能对其应用地址运算符的值。 *将右值关联到右值引用导致该右值被存储到特定的位置,且可以获取该位置的地址 *右值包括字面常量(C风格字符串除外,它表示地址),诸如X+Y等表达式以及返回值得函数(条件是该函数返回的不是引用) *引入右值引用的主要目的之一是实行移动语义 Example: int f(int x,int y) { return原创 2013-07-24 18:31:27 · 1547 阅读 · 0 评论 -
C++11特性--新的类功能--特殊的成员函数(移动构造函数,移动赋值运算符),默认方法和禁用方法(default,delete),委托构造函数,管理虚方法(override,final)
1.新的类功能 (1)特殊的成员函数 *在原有4个特殊成员函数(默认构造函数,复制构造函数,复制赋值运算符和析构函数)的基础上,C++11新增了两个:移动构造函数,移动赋值运算符。这些成员函数式编译器在各种情况下自动提供的。 *如果类定义了移动构造函数或移动赋值运算符,编译器将不会自动提供复制构造函数和复制赋值运算符 *如果类定义了造函数,复制原创 2013-07-25 07:06:03 · 2459 阅读 · 0 评论 -
C++11特性--Lambda函数
1.Lambda函数 *对于接受函数指针或函数符的函数,可以用匿名定义(lambda)作为其参数。 *仅当Lambda表达式完全由一条返回语句组成时,自动类型推断才管用,否则需要使用新增的返回类型后置语法 *当没有返回值时,推断为void Example: [](int x){ return x%2==1;} 解析: []代替了函数名,这里原创 2013-07-25 07:11:30 · 663 阅读 · 0 评论