【发布时间】:2012-05-15 13:20:50
【问题描述】:
#include <iostream>
#include <string>
using namespace std;
string a;
namespace myNamespace
{
string a;
void output()
{
cout << a << endl;
}
}
int main()
{
a = "Namespaces, meh.";
myNamespace::a = "Namespaces are great!";
myNamespace::output();
}
结果是“命名空间很棒!”。那么有什么方法可以访问命名空间 myNamespace 中的全局字符串 a 而不仅仅是本地字符串?
【问题讨论】:
标签: c++ object namespaces global local