Test
{
Test (test& t1)
{
this->t=t1;
}
Private
Test T;
}
I believe a lot of people, like me, are very confused. Why test constructs a constructor that calls test and then calls the assignment operator of the test class. That is because the assignment operator does not produce a new object, and the test constructs a test object when constructed. So the normal process is to construct t before calling the assignment operator Assignment T (THIS->T=T1).
If written
Test
{
Test (test& T1): t (T1)
{
}
Private
Test T;
}
Only the copy constructor of test is called once, and T is constructed. So the initialization list is more efficient than the assignment.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Why the constructor initialization list in C + + is more efficient than assigning values in constructors