在下面的代码中编写语句A::x=5给出了错误:
命名空间“A”中的“x”未命名类型
我们不能为x变量全局赋值吗?
#include <iostream>
int x = 10;
namespace A
{
int x = 20;
}
A::x=5;
int main()
{
int x = 30;
std::cout << "x = " << x << std::endl;
std::cout << "A::x = " << A::x << std::endl;
std::cout << "::x = " << ::x << std::endl;
}
Run Code Online (Sandbox Code Playgroud)