预测以下C++程序的输出。
null
#include<iostream> using namespace std; class Test { private : int x; public : Test( int x = 0) { this ->x = x; } void change(Test *t) { this = t; } void print() { cout << "x = " << x << endl; } }; int main() { Test obj(5); Test *ptr = new Test (10); obj.change(ptr); obj.print(); return 0; } |
(A) x=5 (B) x=10 (C) 编译错误 (D) 运行时错误 答复: (C) 说明: 这是一个常量指针,所以在“this=t 这个问题的小测验
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END