--- 1.cerr与clog:
---------------------- 两者流对象同为标准错误流 两者都不能被重定向(windows) 区别在于 cerr不缓冲而clog缓冲
--- 2.C++操作符替代名:
-------------------------------- 在头文件ciso646中声明 其实就是一堆宏
--- 源码如下:
/* iso646.h standard header */
#pragma once
#ifndef _ISO646
#define _ISO646
#if !defined(__cplusplus) || defined(_MSC_EXTENSIONS)
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif /* !__cplusplus || _MSC_EXTENSIONS */
#endif /* _ISO646 */
--- 3.const:
-------------- const对象默认本文本内有效 const对象可以绑定到非const对象上
-------------- 引用的类型必须与其所引用的对象类型一致 但初始化常量引用时 只要表达式能转换为引用的类型就行
-------------- const对比与宏 可以更加节省空间 因为const常量在运行过程中给出的是对应的内存地址 #define在内存中有若干个拷贝
-------------- 编译器通常不将const常量分配空间 而是放在符号表中 没有了读取操作 使得效率提高
-------------- const 的引用可以绑定到字面值常量上
---ex:
const int &a = 42;
-------------- const修饰指指针别名对于初学者通常有一个陷阱 如下例
---ex:
#include <iostream>
using namespace std;
using pstr = char *;
int main(void){
const pstr a = nullptr;
//经过重新命名后 *并不是声明符的一部分 pstr基本数据类型为指针
//a为指向char的常量指针 而非指向常量char的普通指针
system("pause");
return 0;
}
--- 4. nullptr:
------------------ 在c++中 NULL为0 所以要养成使用nullptr 和 0 的好习惯
---源码如下:
/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
--- 5.constexpr:
--------------------- 很遗憾 vs2012打了补丁也不支持这个 官方给出最低编译器版本vs2015
--------------------- to do
--- 6.定义别名:
-------------------- 用using来定义别名 光标说明显示的还是 typedef
---ex:
using SI = char;
--- 7.decltype:
-------------------- 类型指示符 用于获得类型 而不执行获得类型的过程
-------------------- 若表达式内容为解引用操作 或者 额外加上一层括号(函数不适用) 将得到引用类型
--------------------参数为赋值表达式时 推断出的为左值类型的引用
---ex: