register
定义一个存储在寄存器里的变量,所以不能应用& 的运算符
auto
自动推断
auto f=3.14; //double
auto s("hello"); //const char*
auto z = new auto(9); // int*
auto x1 = 5, x2 = 5.0, x3='r';//错误,必须是初始化为同一类型
static
静态的变量, 不会被销毁, 保存在堆里
extern
通过extern 可以声明别的文件的变量
#include <iostream>
int count ;
extern void write_extern();
int main()
{
count = 5;
write_extern();
}
#include <iostream>
extern int count;
void write_extern(void)
{
std::cout << "Count is " << count << std::endl;
}
Count is 5
thread_local 存储类
线程变量类, 只允许在线程上访问变量
- 无法声明函数
- 可以和static 和extren 配合使用