C++构造函数问题9

预测以下程序的输出。

null

#include<iostream>
#include<stdlib.h>
using namespace std;
class Test
{
public :
Test()
{ cout << "Constructor called" ; }
};
int main()
{
Test *t = (Test *) malloc ( sizeof (Test));
return 0;
}


(A) 构造函数调用 (B) 空的 (C) 编译错误 (D) 运行时错误 答复: (B) 说明: 与new不同,malloc()不调用构造函数(参见 )

如果我们用new替换malloc(),则会调用构造函数,请参阅 . 这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享