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

admin2010-06-06  23

问题 根据输出结果填空完成下面程序。
   # 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. func( );
        a. sfunc(a)
   }

选项

答案int Test::val=200;

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

最新回复(0)