由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - diff between p = new myclass and p = new myclass() ?
相关主题
问个copy constructor的问题这个c++ static var 很有意思
thrust, about the initialization of PODwhat is the difference?
再问C++初始化问题。一个 default constructor 的问题
关于C/C++里的Static variable的memory allocation/initializawhat is the diff between release build and debug build?
为啥 const Base cb 要求Base() {} 而 const vBase vb 不呢?prevent assignment
Question about vector as a class memberstatic initialization dependency c++
前几天有人问rvalue reference的[菜鸟问题]类模板问题
C++弱问one question about initializaiton list
相关话题的讨论汇总
话题: myclass话题: new话题: diff话题: pod话题: class
进入Programming版参与讨论
1 (共1页)
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?
1 (共1页)
进入Programming版参与讨论
相关主题
one question about initializaiton list为啥 const Base cb 要求Base() {} 而 const vBase vb 不呢?
how to initialize associate data in STL mapQuestion about vector as a class member
请问const myClass &src 和myClass const &src有什么区别?前几天有人问rvalue reference的
请问在class member function中如何调用overloaded function caC++弱问
问个copy constructor的问题这个c++ static var 很有意思
thrust, about the initialization of PODwhat is the difference?
再问C++初始化问题。一个 default constructor 的问题
关于C/C++里的Static variable的memory allocation/initializawhat is the diff between release build and debug build?
相关话题的讨论汇总
话题: myclass话题: new话题: diff话题: pod话题: class