预测产量?
null
#include <iostream> using namespace std; class Test { int x; Test() { x = 5;} }; int main() { Test *t = new Test; cout << t->x; } |
(A) 编译错误 (B) 5. (C) 垃圾值 (D) 0 答复: (A) 说明: 存在编译器错误:Test::Test()是私有的。
new调用构造函数。在类测试中,构造函数是私有的(注意,默认访问在C++中是私有的)。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END