由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - one question about initializaiton list
相关主题
问个copy constructor的问题pthread_create inside a constructor
Is the order of initialization a, b, c or c, b, a?c++问题,请高人指点迷津,c++ faq lite的一个例子
抠字眼:assignment and initialize in C++Q on overloaded assignment vs copy constructor.
c++ initialize struct请教问题
一道 memset in C++的题*(&b1)=b编译不过,b1=b可以,区别是?
Re: VC里面的stl支持是不是很弱?static initialization dependency c++
How to initialize object in constructor?what is the difference?
大家谈谈看??how to initialize associate data in STL map
相关话题的讨论汇总
话题: 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版参与讨论
相关主题
how to initialize associate data in STL map一道 memset in C++的题
Is it possible to initialize container in initialization list?Re: VC里面的stl支持是不是很弱?
c++ 不自动initialize变量么?How to initialize object in constructor?
请教几个C++问题大家谈谈看??
问个copy constructor的问题pthread_create inside a constructor
Is the order of initialization a, b, c or c, b, a?c++问题,请高人指点迷津,c++ faq lite的一个例子
抠字眼:assignment and initialize in C++Q on overloaded assignment vs copy constructor.
c++ initialize struct请教问题
相关话题的讨论汇总
话题: list话题: str