单选题 C++
题号 #1491828

将下面类 TestClass 中的函数 fun() 的对象成员 n 值修改为100的语句应该是(          )。
class TestClass
{
public:
TestClass (int x){n=x;}
void SetNum(int n1){n=n1;}
private:
int n;
}
int fun()
{
TestClass *ptr = new TestClass(45);
                    ;
}

进入在线模考

参考答案

B

答案解析

对象指针存放的是对象的地址,要访问对象指针所指向对象的成员。可以通过两种方式。(*指针).成员,或者是 指针->成员。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考