注册 登录
编程论坛 C++教室

请问这个这个程序结果是40还是37~请求解释~谢了

zpjm 发布于 2011-06-27 20:33, 443 次点击
#include <iostream>
using namespace std;
class Test
{
   public:
   static int x;
   Test (int i=0)
   {
       x=i+x;
   }
   int Getnum()
   {
       return Test::x+7;
   }
};
   int Test::x=30;
   void main()
   {
       Test test;
   cout<<test.Getnum()<<endl;
   }

2 回复
#2
sufei12342011-06-27 23:32
37呀   静态变量了  赋值30后  再进入main函数里去执行
#3
ToBeStronger2011-06-27 23:34
果断37啊。不知道40是怎么想的.......
1