boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - one question about initializaiton list
相关主题
问个copy constructor的问题
Is the order of initialization a, b, c or c, b, a?
抠字眼:assignment and initialize in C++
c++ initialize struct
一道 memset in C++的题
Re: VC里面的stl支持是不是很弱?
How to initialize object in constructor?
大家谈谈看??
pthread_create inside a constructor
c++问题,请高人指点迷津,c++ faq lite的一个例子
相关话题的讨论汇总
话题: list话题: str
进入Programming版参与讨论
1 (共1页)
c***g
发帖数: 472
1
one statement said "The compiler iterates over the initialization list, inse
rting the initializations in the proper order within the constructor prior t
o any eplicit user code"
That's is to say, some codes are inserted to the constructor.
So why initialization list is much more efficient than constructor? just
avoid assignment operator?
What does "insert" here mean?
w*****n
发帖数: 9
2
We can think the execution of constructor as 2 phase:
1) an implicit or explicit initialization phase
2) a general computation phase.
class A
{
public:
A();
private:
string _str;
double _a;
}
A::A()
{
_str = "";
_a = 0.0;
}
Here, before the A() is executed, the default string constructor is used for
_str implicitly. This means _str = "" is unnecessary.
A member class object should always be initialized in the member
initialization list.

inse
t

【在 c***g 的大作中提到】
: one statement said "The compiler iterates over the initialization list, inse
: rting the initializations in the proper order within the constructor prior t
: o any eplicit user code"
: That's is to say, some codes are inserted to the constructor.
: So why initialization list is much more efficient than constructor? just
: avoid assignment operator?
: What does "insert" here mean?

1 (共1页)
进入Programming版参与讨论
相关主题
c++问题,请高人指点迷津,c++ faq lite的一个例子
Q on overloaded assignment vs copy constructor.
请教问题
*(&b1)=b编译不过,b1=b可以,区别是?
static initialization dependency c++
what is the difference?
how to initialize associate data in STL map
Is it possible to initialize container in initialization list?
c++ 不自动initialize变量么?
请教几个C++问题
相关话题的讨论汇总
话题: list话题: str