问题
填空题
对于下面定义的类MyClass,请在函数f( )中添加对象成员把n的值修改为50。 class MyClass { public: MyClass(intx) {n=x;} void SetNum(int nl) {n=nl;} private: int n; }; int f( ) { MyClass * ptr=new MyClass(45) ; }
答案
参考答案:ptr->SetNum(50) ;
解析: 本题考查的是考生使用对象指针调用成员函数的能力,指针调用成员函数应该使用符号“- >”。