我知道如果一个变量是全局的,你总是可以通过在变量名前加上来访问它的值::......但是有没有办法访问隐藏在另一个范围内的局部变量的值?
我想到这样的事情:
void f() {
int x = 1;
{
int x = 2;
//access the value of the variable x (with the 1 in it) inside here
}
}
Run Code Online (Sandbox Code Playgroud)
如果语言不支持这个,那么我对一些hacky解决方案完全没问题.
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |