当前位置: 首页 > article >正文

侯捷 C++ 课程学习笔记:C++ 新标准11/14

 演进、环境与资源

C++2.0 (C++11/14)新特性

语言(只谈新东西),需要具备,C++ 语法和语意的基础

C++ Standard 之演化

C++ 98(1.0)、C++ 03(TR1,Technical Report 1)、C++ 11(2.0)、C++ 14。

C++ 2.0 新特性包括语言和标准库两个层面,后者以 header files 形式呈现。

C++ 标准库的 header files 不带副档名(.h),如 #include <vector>

新式 C header files 不带副名称 .h,如 #include <cstdio>

旧式 C header files (带有副名称 .h )仍可用,如 #include <stdio.h>

旧式换新式:就是将<stdio.h>改写成<cstdio> 相当于在“stdio”前面加上 c ,后面删除 .h。

仍然可以使用旧式,旧式还是可以完全正常工作的,不过还是适应更换新式

C++ 2.0 新添加的头文件

#iinclude <type_traits>

#iinclude <unordered_set>

#iinclude <forward_list>

#iinclude <array>

#iinclude <tuple>

#iinclude <regex>

#iinclude <thread> 这些都在 using namespace std  

many of TR1 features(特性) that existed(存放) in nameespace 

std::tr1 in the previous release (like shared_pptr and regex) are now part of the standard library under the std namespace.(tr1 特性存放在std::tr1,现在存放在std)

了解使用的编译器对C++ 2.0 的支持度

可以在 Standard C++ 、C++ Rocks! 、谷歌、华为等检索查看。

Dev-C++ 5.11,MinGW with GCC 4.9.2(平台外挂 编译器 GCC)

Dev-C++ 上的ISO C++11 开关(使用Dev-C++)其他平台可能类似有如此开关。

开关位置:点击左上角 “Project”,找到并选择 “Compiler” ,在 “Customize(applies to this project only)”中找到并选择 “Code Generation” 最下面 “Language standard(-std)” 选项中选择 “ISO C++11” (Language standard(-std) 选项中有 ISO C90、ISO C99、ISO C++、ISO C++11、GUN C90、GUN C99、GUN C++、GUN C++11)。

 C++11 FAQ C++ FAQ from Strousstrup

编程时可以查阅的网页

cplusplus.com 、cppreference.com 、GCC, the GNU Compiler Collection- GNU Project (似乎是外网网站)

建议选择使用一款顺手的全文检索工具(帮助我们查看标准库代码)

Test-C++2.0.cpp

第一步,确认支持C++11:macro__cplusplus

Variadic Templates

第一颗震撼弹 Variadic Templates

数量不定的模版参数

... 就是一个所谓的 pack (包) 用于 template paramenters,就是template paramenters pack(模版参数包)

                                                  用于function paramenter  types,就是  function paramenter  types pack(函数参数类型包)

                                                  用于function paramenter ,就是function paramenter pack(函数参数包)

Space in Template Expression、nullptr and stdnull

The requirement to put a space between two closing template expressions has gone。

vector<list<int> >;  // OK in each C++ version

vector<list<int>>;   // OK since C++11

nullptr and std::nullptr_1

C++11 lets you use nullptr instead of 0 or NULL to specify that a spointer refers to no value(which differs from having an undefined value).This new feature especially helps to avoid mistakes that occurred when a null pointer was interpreted as an integral value.For example:

void f(int);

void f(void*);

f(0);               // calls f(int)

f(NULL);        // calls f(int) ifNULL is 0,ambiguous otherwise

f(nullptr);       //calls f(void*)

nullptr is a new keyword.It automatically converts into each pointer type but not to any integral type.It has type std::nullptr_t,defined in <cstddef> (see Section 5.8.1,page161),so you can now evwn overfload operations for the case that a null point is passed.Note that std::nullprt_t counts as a fundamental date type (see Section 5.4.2,page 127).

Automatic Type Deduction with auto

With C++11, you can declare a variable or an object without specifying its specific type by using auto.For example:

auto i =42;//i has type int

double f();

auto d = f();//d has type double

Using auto is especially useful where the type is a pretty long and/or complicater expression.For example:

vector<string> v;

... 

auto pos = v.begin();       //pos has type vector<string>::iterator

注:有不当之处,请批评指正!谢谢~


http://www.kler.cn/a/582324.html

相关文章:

  • 使用AI一步一步实现若依前端(8)
  • vue3 二次封装uni-ui中的组件,并且组件中有 v-model 的解决方法
  • Vue 实现AI对话和AI绘图(AIGC)人工智能
  • Excel多级联动下拉菜单设置
  • C盘清理技巧分享:释放空间,提升电脑性能
  • Networking Based ISAC Hardware Testbed and Performance Evaluation
  • [动手学习深度学习]13.丢弃法 Dropout
  • 修改jupyter notebook的工作空间
  • 二级Python通关秘籍:字符串操作符/函数/方法全解析与实战演练
  • Spike RISC-V ISA 模拟器
  • 三级嵌入式学习ing 考点25、26
  • python-leetcode-解决智力问题
  • 常见的死锁情况分析
  • JDBC编程六步详解:从注册驱动到释放资源
  • C++学习笔记(十七)——类之封装
  • LETTERS(dfs)
  • Spring 的三种注入方式?
  • Vue3 + Spring Boot前后端分离项目跨域问题完整解决方案
  • C++编程:进阶阶段—4.2对象
  • Spring MVC 工作原理和流程