首页 > 技术文章 > C++11 new feature

graph 原文

  1. C++11 在类中引入了Move Constructor and the Move Assignmnt Operaetor,所谓‘move’指的是在复制对象时,left object 不用再创建资源,直接把right object 的资源当做自己的来用。而right object 的资源将全部被设置为default ,即为empty object 。
    1. http://blog.smartbear.com/c-plus-plus/c11-tutorial-introducing-the-move-constructor-and-the-move-assignment-operator/
  2. 引入了关键字auto 和 decltype ,有了auto可以在定义变量时不用指出变量的类型,编译器自己推断出变量的类型。auto 的最大用我自己感觉有两点: (1)有些太长的类型比如STL的一些迭代器的类型定义时可以省去左边的长串字符的书写,由编译器自己去推断类型;(2)当auto 和template结合在一起时可以写出更加灵活的代码,此时可能需要借助decltype来推测输出的类型。
    1. http://blog.smartbear.com/c-plus-plus/c11-tutorial-let-your-compiler-detect-the-types-of-your-objects-automatically/
    2. http://blog.csdn.net/fire_lord/article/details/8499596
  3. 类的继承控制关键字:override 和 final .在类的继承中有时需要在derived的class中对虚函数进行重写,但这个地方很容易出现错误是的derived class 中“重写”的函数和based class的函数签名不一致,使得原本打算进行的重写变成了定义新的函数。如果加了override关键字,编译器会自动检查函数签名是否和based class的函数签名是否一致。而final关键字则使得类和类中一些函数不能再继承。要注意下这两个关键字不是reserved keyword 而是 CSK(context sensitive keywords),即只有在适当的contex下才会被当做keyword .
    1. http://blog.smartbear.com/c-plus-plus/use-c11-inheritance-control-keywords-to-prevent-inconsistencies-in-class-hierarchies/
    2. http://blog.csdn.net/fire_lord/article/details/8540592
  4. Lambda Expressions (匿名函数)。语法结构:[capture clause](parameters)->return-type{body} 。有人说引入这主要原因是function programering 的流行,可能我自己对于函数式编程不是很了解,所以无法领会它的强大。lambda Expessions有三个优势:1)提供了比function class 更加convinent 的工具,因为其不用定义构造函数以及member,2)编译器对其作出的优化比一般的函数更大;3)其比一般的函数有更大的security,因为lambda expession 是local的。 
    1. http://blog.smartbear.com/c-plus-plus/c11-tutorial-lambda-expressions-the-nuts-and-bolts-of-functional-programming/
    2. http://ciere.com/cppnow12/lambda.pdf
    3. http://blog.csdn.net/srzhz/article/details/7934652
  5. 强类型的enum,主要解决enum 的命名冲突问题。定义时需要在enum后面加上class 关键字。不过强类型的enum不支持和int 的转换,刚习惯的enum在类中定义数组的长度以及索引,看来还是要使用old enum style 来进行。
    1. http://blog.smartbear.com/c-plus-plus/closer-to-perfection-get-to-know-c11-scoped-and-based-enum-types/
  6. right reference 
    1. http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
  7. constexpr 
    1. http://blog.smartbear.com/c-plus-plus/using-constexpr-to-improve-security-performance-and-encapsulation-in-c/

 

http://msdn.microsoft.com/en-us/library/vstudio/hh279654.aspx

http://www.cnblogs.com/hujian/archive/2012/12/08/2809298.html

http://www.codeproject.com/Articles/570638/Ten-Cplusplus11-Features-Every-Cplusplus-Developer

http://blog.smartbear.com/c-plus-plus/the-biggest-changes-in-c11-and-why-you-should-care/

http://blog.csdn.net/fire_lord/article/category/1324600

推荐阅读