当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 在哪找可以下到xml的帮助文档 谢谢各位了 :) 如果谁有 请联系我 好吗 谢谢! qq:29385561 交个朋友! :p ......
    摘要: http://www.51test.net/show.asp?id=2723 高校漂亮mm 看看你们认识几个没有 北大那个有味 ......


帮忙C++的变量的作用范围

#include   <iostream>  
  #include   <conio.h>  
  using   namespace   std;  
   
  int   x   =   100;  
   
  class   WithStatic   {  
      static   int   x;  
      static   int   y;  
  public:  
      void   print()   const   {  
          cout   <<   "WithStatic::x   =   "   <<   x   <<   endl;      
          cout   <<   "WithStatic::y   =   "   <<   y   <<   endl;    
      }  
  };  
   
  int   WithStatic::x   =   1;  
  int   WithStatic::y   =   x   +   1;     /*这里的x为什么不是全局变量里面的那个值为100的x?如果换成int   WithStatic::y   =   ::x   +   1;   使用的就是那个100的X,这是为什么?::不是域的符号吗?*/  
   
  void   main()   {  
      WithStatic   ws;  
      ws.print();  
      getch();  
  }    
   
   
  请赐教!!!!!!!  
   
  //   VC6、VC7的编译后的输出结果都是:X=1,Y=2。  
   
 

NO.1   作者: bigwhiteshark

是域的符号但是前面要加类名

NO.2   作者: junguo

::x表示的是全局域的x,如果要用类域的静态变量应该是  
  int   WithStatic::y   =   WithStatic::x   +   1;

NO.3   作者: lifanxi

int   WithStatic::y   =   x   +   1;  
  等于  
  int   WithStatic::y   =   WithStatic::x   +   1;  
  因为前面的WithStatic就为表达式右边打开了WithStatic这个类域。  
  int   WithStatic::y   =   ::x   +   1;  
  因为这里的::表示全局域,所以::x就是100,最后WithStatic::y就为101


 ·如何格式化输出float型值    »显示摘要«
    摘要: 有个变量v=1234.56789 我要在out.print时小数点后只显示两位(1234.56),如何做? ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE