#include<stdio.h>
namespace n1
{
int x;
}void pp()
{
printf("x is %d\n",n1::x);
}void main()
{
n1::x=2;
pp();
}调试时,可以在watch窗口中看见n1::x的值,但如果用using namespace n1;的话,在watch窗口中就不会显示x的值,而是会提示cx0017:error :symbol "x" not found,但如不定义n1,而直接定义全局变量x,则鼠标悬停时和watch窗口都会显示x的值,请问是怎么回事?

解决方案 »

  1.   

    namespace Declaration
    C++ Specific —>namespace [identifier] { namespace-body }A namespace declaration identifies and assigns a name to a declarative region.The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.The declarative region of a namespace declaration is its namespace-body.
      

  2.   

    试了下vc是有这个问题,不能看using namespace里的变量,下,看下gdb是否有这个问题
      

  3.   


    如上图,使用using namespace n1后,如想在watch窗口中观察x值,应该加::修饰符。
    逻辑上这也是合理的,如果不加::修饰符,当再有另外一个名字空间中存在x变量,watch窗口将无法区分。
      

  4.   

    VC的BUG,用VS2008试下,看看怎么样。