本文共 995 字,大约阅读时间需要 3 分钟。
0. 几个零星知识点
. 嵌套作用域:局部变量会覆盖全局变量
. char 在有些机器有符号,有的无符号。 . 标识符大小写敏感。1.变量声明和定义
c++ 将声明和定义分开来。
声明 extern int i;// 指定变量名字、类型
定义 extern double pi = 3.45; //申请存储空间、为变量赋初值变量可以声明多次,定义一次.
eg.
shareVariable.h
#ifndef SHAREVARIABLE_H #define SHAREVARIABLE_H extern int nShare;// 指定变量名字、类型#endif
useShareVariable1.h
#ifndef USESHAREVARIABLE1_H #define USESHAREVARIABLE1_H #include#include "shareVariable.h"extern int nShare = 1;// 定义变量class useShareVariable1 { public: void static test() { std::cout << nShare; }};#endif
useShareVariable2.h
#ifndef USESHAREVARIABLE2_H #define USESHAREVARIABLE2_H #include#include "shareVariable.h" extern int nShare;//声明变量,该句也可以忽略class useShareVariable2 { public: void static test() { std::cout << nShare; }};#endif
2. c++关键字
我不认识的:decltype
asm constexpr const_cast mutable noexcept thread_local static_cast staitic_assert reinterpret_cast volatile3. c++操作符替代名
[1]: 代码 https://github.com/thefistlei/cplusprimer/tree/main/cprimer
转载地址:http://jbuz.baihongyu.com/