博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
static变量初始化
阅读量:4154 次
发布时间:2019-05-25

本文共 719 字,大约阅读时间需要 2 分钟。

1.在C++中,全局static变量和class的static成员变量在main函数之前初始化,main函数之后销毁

2. 函数内部的局部static变量在该函数第一次被调用时初始化,在main函数之后销毁

3.对于static数据即使是函数内部的对象则存放在全局数据区,全局数据区的数据并不会因为函数的退出就将空间释放。

#include 
using namespace std;struct Date{ Data(){cout<<"create"<

output:

create

main begin
main end
destroy

#include 
using namespace std;struct Date{Data(){cout<<"create"<
<<"destroy"<
output:

create

main begin
main end
destroy

#include 
using namespace std;struct Date{Data(){cout<<"create"<
<<"destroy"<

main begin

first
create
second
main end
destroy

在看一个比较BT的题目。

在系统中只能调用一次函数

void caller(){	cout<<"first call\n";}void FirstCall(){	static int d = (caller(),1);}int main(){	FirstCall();	FirstCall();}

转载地址:http://xieti.baihongyu.com/

你可能感兴趣的文章
我对C++ string和length方法的一个长期误解------从protobuf序列化说起(没处理好会引起数据丢失、反序列化失败哦!)
查看>>
一起来看看protobuf中容易引起bug的一个细节
查看>>
无protobuf协议情况下的反序列化------貌似无解, 其实有解!
查看>>
make -n(仅列出命令, 但不会执行)用于调试makefile
查看>>
makefile中“-“符号的使用
查看>>
go语言如何从终端逐行读取数据?------用bufio包
查看>>
go的值类型和引用类型------重要的概念
查看>>
求二叉树中结点的最大值(所有结点的值都是正整数)
查看>>
用go的flag包来解析命令行参数
查看>>
来玩下go的http get
查看>>
队列和栈的本质区别
查看>>
matlab中inline的用法
查看>>
如何用matlab求函数的最值?
查看>>
Git从入门到放弃
查看>>
java8采用stream对集合的常用操作
查看>>
EasySwift/YXJOnePixelLine 极其方便的画出真正的一个像素的线
查看>>
Ubuntu系统上安装Nginx服务器的简单方法
查看>>
Ubuntu Linux系统下apt-get命令详解
查看>>
ubuntu 16.04 下重置 MySQL 5.7 的密码(忘记密码)
查看>>
Ubuntu Navicat for MySQL安装以及破解方案
查看>>