d********t 发帖数: 9628 | 1 请问
p = new myclass
和
p = new myclass()
有何区别?
谢谢! |
t****t 发帖数: 6806 | 2 no difference for user-defined class. for built-in types, () will do 0-
initialize.
【在 d********t 的大作中提到】 : 请问 : p = new myclass : 和 : p = new myclass() : 有何区别? : 谢谢!
|
X****r 发帖数: 3557 | 3 Same for non-POD class, e.g. if myclass has defined a constructor.
But they are different for POD class,
e.g. struct myclass {int a; int b;};
new myclass creates an object with indeterminate values, while
new myclass() creates an object zero-initialized.
【在 d********t 的大作中提到】 : 请问 : p = new myclass : 和 : p = new myclass() : 有何区别? : 谢谢!
|
X****r 发帖数: 3557 | 4 好吧,你快一点点,我自砰。
【在 t****t 的大作中提到】 : no difference for user-defined class. for built-in types, () will do 0- : initialize.
|
d********t 发帖数: 9628 | 5
1. 啥叫POD class?
2. 如何是
class myclass
{
int a;
int b;
}
呢?
【在 X****r 的大作中提到】 : Same for non-POD class, e.g. if myclass has defined a constructor. : But they are different for POD class, : e.g. struct myclass {int a; int b;}; : new myclass creates an object with indeterminate values, while : new myclass() creates an object zero-initialized.
|
f******y 发帖数: 2971 | 6 Why does it work this way?
【在 t****t 的大作中提到】 : no difference for user-defined class. for built-in types, () will do 0- : initialize.
|
t****t 发帖数: 6806 | 7 because standard said so.
【在 f******y 的大作中提到】 : Why does it work this way?
|