1. Trang chủ
  2. » Công Nghệ Thông Tin

Những điểm mới từ C++ tới C++11

52 486 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 52
Dung lượng 1,14 MB

Nội dung

Những điểm mới của C++11 so với C++. C++11 là một chuẩn mới được cải tiến dựa trên những căn bản của ngôn ngữ lập trình C++....auto variable nullptr Rangebased for loops decltype Uniform Initialization Initializer Lists Override and final Stronglytyped enums Lambdas Smart pointers static_assert and type traits Move semantics rvalue reference thread

From C++ to C++11 Hoàng Mạnh Hưng hung.hoangmanh2@gameloft.com May 2015 What is C++11? Important changes Getting started What is C++11? Important changes Getting started What is C++11? • • ISO Standard approved on August 2011 Other name: C++0x What is C++11? Important changes Getting started Important changes ➢ auto variable ➢ Strongly-typed enums ➢ nullptr ➢ Lambdas ➢ Range-based for loops ➢ Smart pointers ➢ decltype ➢ static_assert and type ➢ Uniform Initialization & Initializer Lists ➢ traits ➢ Move semantics & rvalue reference Override and final ➢ thread auto variable Earlier Version int i = 42; long long l = 42LL; void (*p)(int, float, char) = foo; // void foo(int, float, char) vector::iterator Version11 it = v.begin() // v has type auto vector i = 42; // i has type int auto l = 42LL; // l has type long long auto p = &foo; // p is pointer point to void foo function auto it = v.begin() // v has type vector auto l =[] (int x) -> bool { //l has the typeof a lambda nullptr • • • New keyword Avoid implicit conversion to integral types Has type std::nullptr_t Range-based for loops • So-called “foreach” loop Example 1: for (auto i : {1,2,3,4,5}) { std::cout [...]... 12 Uniform Initialization & Initializer Lists (cont.) class C { int a; int b; int arr[4]; public: C() : arr{1,2,3,4}{} / /C++1 1, member array initializer C(int i, int j) : a(i), b(j){} }; void main() { C c {0,0}; / /C++1 1 only Equivalent to: C c(0,0); int* a = new int[3] { 1, 2, 0 }; /C++1 1 only } 13 Uniform Initialization & Initializer Lists (cont.) • Prevent narrowing: int x1(5.3); // OK, but x1 becomes... decltype(a[0]*b[0]) Tmp; for (int i=0; i return-type {body} • [capture] ● [a,&b] a captured by value, b captured ...What is C++1 1? Important changes Getting started What is C++1 1? Important changes Getting started What is C++1 1? • • ISO Standard approved on August 2011 Other name: C++0 x What is C++1 1? Important... type auto vector i = 42; // i has type int auto l = 42LL; // l has type long long auto p = &foo; // p is pointer point to void foo function auto it = v.begin() // v has type vector... arr{1,2,3,4}{} / /C++1 1, member array initializer C(int i, int j) : a(i), b(j){} }; void main() { C c {0,0}; / /C++1 1 only Equivalent to: C c(0,0); int* a = new int[3] { 1, 2, }; /C++1 1 only } 13

Ngày đăng: 12/04/2016, 23:59

TỪ KHÓA LIÊN QUAN

w