下列程序的运行结果为【 】。 #include <iostream. h> class myclass { private: int a, b, c; public

admin2010-06-06  21

问题 下列程序的运行结果为【 】。
      #include <iostream. h>
      class myclass
      {
        private:
             int a, b, c;
       public:
             void fun()
             {
             int a;
             a=10;
             this->,a=5;
             b=6;
             this->c=7;
             cout<<"a="<<a<<",this->a="<<this->a<<endl;
             }
      };
      void main()
      {
            myclass obj1;
            obj1.fun()
      }

选项

答案a=10, this->a=5

解析 本题考察在类的成员函数定义中,如果出现类的数据成员和成员函数的局部变量同名的情况下,如何正确引用合适的变量或数据成员。本题巧妙的采用了this指针完成这种标识。
转载请注明原文地址:https://kaotiyun.com/show/V4jp777K
0

最新回复(0)