由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ initialize struct
相关主题
问一个 copy constructor 的问题 (C++)不明白C++的一个地方
问个copy constructor的问题find bugs of c++ codes
急问:compile and build dependencyIs the order of initialization a, b, c or c, b, a?
码工试题 (转载)one question about initializaiton list
抠字眼:assignment and initialize in C++C++ question
几个问题如何 initialize array member?
c++问题,请高人指点迷津,c++ faq lite的一个例子static initialization dependency c++
C++ 中 myobject * a =new myobject[n] 的问题Test your C++ knowledge...
相关话题的讨论汇总
话题: struct话题: default话题: ctor话题: c++
进入Programming版参与讨论
1 (共1页)
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!
1 (共1页)
进入Programming版参与讨论
相关主题
Test your C++ knowledge...抠字眼:assignment and initialize in C++
请教问题几个问题
一道 memset in C++的题c++问题,请高人指点迷津,c++ faq lite的一个例子
question about c++ constructorC++ 中 myobject * a =new myobject[n] 的问题
问一个 copy constructor 的问题 (C++)不明白C++的一个地方
问个copy constructor的问题find bugs of c++ codes
急问:compile and build dependencyIs the order of initialization a, b, c or c, b, a?
码工试题 (转载)one question about initializaiton list
相关话题的讨论汇总
话题: struct话题: default话题: ctor话题: c++