本文介绍了我有关于在命名空间中初始化变量的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>

using namespace std;

namespace AAA
{
	namespace BBB
	{
		namespace CCC
		{
			int num1, num2;
		}
	}
}

int main()
{
	namespace ABC = AAA::BBB::CCC;
	cout << ABC::num1 << ABC::num2 << endl;
	return 0;
}





我的尝试:



如您所见,我没有在命名空间AAA :: BBB :: CCC中初始化变量num1,num2。在正常情况下,num1和num2应该有垃圾值是正确的,但我确认编译后它们都是0。为什么?



What I have tried:

As you see, I didn't initialize variable num1, num2 in namespace AAA::BBB::CCC. In the normal case, It is correct that num1 and num2 should have garbage values, but I have confirmed that both were 0 after compilation. Why?

推荐答案


这篇关于我有关于在命名空间中初始化变量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:10