Is there a way to access the value of a local variable that has become hidden inside another scope?

前端 未结 4 466
野的像风
野的像风 2020-12-11 19:38

I know if a variable is global, the you can always access its value by preceding the variable name with ::... but is there a way to access the value of a local

4条回答
  •  悲&欢浪女
    2020-12-11 20:35

    I don't think so. Unless the shadowed variable is a global variable, a variable in another namespace or a member variable of the class or of any of its ancestors or of any other class, it remains inaccessible.

    There might be some compiler-specific trickery with the using keyword, but I wouldn't trust it.

    By the way, using is very useful if you accidentally "shadow" a method in a subclass with a method of the same name but different signature.

提交回复
热议问题