; return 0;
}
void other() {
int y = 1;
cout << "Other: " << x << ", " << y << endl;
}
//file2.cpp
#include<iostream>
using namespace std;
extern int x;
namespace {
int y = -4;
}
void another() {
cout << "another(): " << x << ", " << y << endl;
}
答:
10
4
0
Other: 10, 1
another(): 10, -4
7.下面代码将显示什么内容?
#include<iostream>
using namespace std;
void other();
namespace n1{
int x = 1;
}
namespace n2 {
int x = 2;
}
int main() {
using namespace n1;
cout << x << endl;
{
int x = 4;
cout << x << ", " << n1::x << "," << n2::x << endl;
}
using n2::x;
cout << x << endl;
other();
return 0;
}
void other() {
using namespace n2;
cout << x << endl;
{
int x = 4;
cout << x << ", " << n1::x << ", " << n2::x << endl;
}
using n2::x;
cout << x << endl;
}
答:
1
4, 1, 2
2
2
4, 1, 2
2