Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: A* pA = 新 A 之间的差异;和 A* pA = 新 A(); 变量初始化(指针和值)
假设MyClass有一个默认构造函数,有什么区别
MyClass
MyClass *mc = new MyClass;
和
MyClass *mc = new MyClass();
假设 MyClass 有一个默认构造函数
代码中有 2 个额外字符。
如果该类是 POD 类型(不是您的情况),则后者将执行value-initialization。