m******t 发帖数: 4077 | 1 下面这种情况
struct X {
int i;
int j;
}
X x1 = {1, 2};
是直接把value assign给i,j了吗? 这个过程中default constructor做了什么事情吗? |
c*********e 发帖数: 16335 | 2 struct有constructor?
吗?
【在 m******t 的大作中提到】 : 下面这种情况 : struct X { : int i; : int j; : } : X x1 = {1, 2}; : 是直接把value assign给i,j了吗? 这个过程中default constructor做了什么事情吗?
|
m******t 发帖数: 4077 | 3 难道c++里面的struct不就是class吗?default public就是了。
【在 c*********e 的大作中提到】 : struct有constructor? : : 吗?
|
c*********e 发帖数: 16335 | 4 struct没有constructor/destructor.没有inheritance.
【在 m******t 的大作中提到】 : 难道c++里面的struct不就是class吗?default public就是了。
|
m******t 发帖数: 4077 | 5 I think you are wrong, see "thinking in C++" chapter 6.
【在 c*********e 的大作中提到】 : struct没有constructor/destructor.没有inheritance.
|
t****t 发帖数: 6806 | 6 0分
【在 c*********e 的大作中提到】 : struct没有constructor/destructor.没有inheritance.
|
t****t 发帖数: 6806 | 7 in this case, struct X is called an "aggregate", i.e. you have no user-
defined ctor, no private, no base, no virtual; then you can use initializer
list.
by definition, default ctor is used when no initializer is used, so in your
case it does not apply.
吗?
【在 m******t 的大作中提到】 : 下面这种情况 : struct X { : int i; : int j; : } : X x1 = {1, 2}; : 是直接把value assign给i,j了吗? 这个过程中default constructor做了什么事情吗?
|
c*********e 发帖数: 16335 | 8 看错了,以为是说的c.和和
【在 m******t 的大作中提到】 : I think you are wrong, see "thinking in C++" chapter 6.
|
m******t 发帖数: 4077 | 9 这种情况compiler还generate default constructor吗? 如果是的话,ctor做什么事
情吗?
initializer
your
【在 t****t 的大作中提到】 : in this case, struct X is called an "aggregate", i.e. you have no user- : defined ctor, no private, no base, no virtual; then you can use initializer : list. : by definition, default ctor is used when no initializer is used, so in your : case it does not apply. : : 吗?
|
t****t 发帖数: 6806 | 10 as long as you don't declare a constructor, compiler will declare a default
constructor for you. whether the default ctor will be defined depends on
whether you "use" it to declare object, and in your case, you have not "used
" it so far, so the answer is "not yet". so if later you say
X x10;
then compiler will define a default ctor for you.
【在 m******t 的大作中提到】 : 这种情况compiler还generate default constructor吗? 如果是的话,ctor做什么事 : 情吗? : : initializer : your
|
l*********s 发帖数: 5409 | 11 yes.
does nothing.
【在 m******t 的大作中提到】 : 这种情况compiler还generate default constructor吗? 如果是的话,ctor做什么事 : 情吗? : : initializer : your
|
j*****g 发帖数: 16 | 12 Just wondering if it is possible to prove the default constructor is not
created before it is used. Thanks! |