Ответ 1
С изменой:
int x = 1;
int main(int argc, char* argv[])
{
int x = 2;
{
int& ox = x;
int x = 3;
cout << x << endl;
cout << ::x << endl;
cout << ox << endl;
}
getch();
return 0;
}
Посмотрите на этот фрагмент кода
int x = 1;
int main(int argc, char* argv[])
{
int x = 2;
{
int x = 3;
cout << x << endl;
cout << ::x;
}
getch();
return 0;
}
Когда я вызываю x из блока, я получаю 3. Когда я вызываю:: x, я получаю 1. Можно ли вызывать x равным 2 изнутри блока?
С изменой:
int x = 1;
int main(int argc, char* argv[])
{
int x = 2;
{
int& ox = x;
int x = 3;
cout << x << endl;
cout << ::x << endl;
cout << ox << endl;
}
getch();
return 0;
}
Нет, это невозможно сделать.