根据输出结果填空完成下面程序。 #include<iostream.h> class Test { private: static int val; int a; public: st

admin2010-12-16  18

问题 根据输出结果填空完成下面程序。
   #include<iostream.h>
   class Test
   {
   private:
       static int val;
       int a;
   public:
       static int func( );
       void sfunc(Test &r);
   };
   ______//初始化静态变量val
   int Test::func( )
   {
       return val++;
   }
   void Test::sfunc(Test &r)
   {
       r.a=125;
       cout<<"Result3="<<r.a;
   }
   void main( )
   {
       cout<<"Resultl="<<Test::func( )<<endl;
       Test A;
       cout<<"Result2="<<A.fune( )<<endl;
       A. sfunc(A);
   }
   输出结果为:
   Result1=201
   Result2=202
   Result3=125

选项

答案int Test::val=200;

解析 类的静态成员变量必须要进行初始化才能使用,初始化时需要用域限定符::指明该变量所属的类名。
转载请注明原文地址:https://jikaoti.com/ti/EHL0FFFM
0

最新回复(0)