C++11/14新特性快速概览

来源:互联网 发布:视频软件截gif 编辑:程序博客网 时间:2024/05/16 05:13
推荐几篇关于C++11/14新特性的文章,是一个系列的,可以快速了解那些新特性,并配有简单移动的代码示例: 
1. 关于初始化列表的,例如使用形如{1, 2, 3, 4, 5}为以前并不支持此种初始化方法的结构初始化,例如:std::vector等等。 
http://www.bogotobogo.com/cplusplus/C11/C11_initializer_list.php 
2. 更统一的初始化方式: 
http://www.bogotobogo.com/cplusplus/C11/C11_Uniform_initialization.php 
3. auto关键字以及基于范围的for循环(for(int i : tempArray){…}): 
http://www.bogotobogo.com/cplusplus/C11/C11_Type_Inference_auto_range_based_for_loop.php 
4. nullptr用以解决以前的NULL与0无法区分的问题,以及强类型枚举(enum class Month { January, February, March };),用以解决原来的弱类型枚举可以跨枚举进行比较的问题: 
http://www.bogotobogo.com/cplusplus/C11/C11_nullptr_strong_typed_enums.php 
5. 编译期静态断言(static_assert)以及代理构造函数(是指构造/拷贝构造函数中调用构造函数:A(int a) : A() { doSomethingElse(); } A(const A& b) : A(){ m_a = b.m_a;}): 
http://www.bogotobogo.com/cplusplus/C11/C11_static_assertion_constructor_delegation.php 
6. override和final标识符,这个应该是借鉴自java,override是为了防止由于参数类型写错导致子类覆盖(而不是重载)了父类的同名方法,相应的,final是为了防止某个类被继承或者某个方法被重载: 
http://www.bogotobogo.com/cplusplus/C11/C11_override_final.php 
7. delete和default说明符,主要是用来强制编译器生成或者不生成某些默认函数(无参构造,拷贝构造,赋值构造等等): 
http://www.bogotobogo.com/cplusplus/C11/C11_default_delete_specifier.php 
8. constexpr(用来表明函数的返回值为常量,以方便编译器进行代码优化)以及字符串前缀修饰符: 
http://www.bogotobogo.com/cplusplus/C11/C11_constexpr_string_literals.php 
char * a = u8”string”; // UTF-8 string 
char16_t* b = u”string”; // UTF-16 
char32_t* c = U”string”; // UTF-32 
char* r = R”string”; // raw string 
9. lambda表达式,这个是一个重头戏了: 
http://www.bogotobogo.com/cplusplus/C11/C11_lambda_functions_expressions.php 
10. std::array容器,这个貌似是来源于boost库的: 
http://www.bogotobogo.com/cplusplus/C11/C11_std_array_container_class.php 
11. 左值引用和右值引用,有了右值引用可以避免好多不必要的临时对象的产生: 
http://www.bogotobogo.com/cplusplus/C11/4_C11_Rvalue_Lvalue.php 
12. move语义,这个可以结合上一条右值引用来看: 
http://www.bogotobogo.com/cplusplus/C11/5_C11_Move_Semantics_Rvalue_Reference.php 
13. thread: 这个也是一些列关于的文章,稍微整理下稍后发出来。
原创粉丝点击