|
|
|
|
|
|
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?
|
|
|
|
|
|
|