不设置静态变量判断一个静态类是否已经初始化

不用静态变量的话可以增加代码的简洁度,采用静态函数代替,由于返回的是引用,所以该函数可以直接赋值,
isStartedUp()=true;其次由于静态变量在函数块内部只初始化一次并存在,所以可以一直使用

/** Checks has the Module been started up. */
static bool& isStartedUp()
{
	static bool inst = false;
	return inst;
}

猜你喜欢

转载自blog.csdn.net/shujianlove0/article/details/84749864