b*******e 发帖数: 34 | 1 How many constructor (including copy constructor) and destructors will be
called for test1 and test2?
Test1:3 constructors and destructors
Step-1 Default constructor will be called at Base a;
Step-2 Copy constructor will be called when passing a as formal parameter i.
e func(a).
Step-3 Copy constructor will be called for return object.
Step-4 Destructor will be called for actual parameter of func.
Step-5 Now this return obj will act as nameless obj in test1() and will get
destroy after line func |
g*******y 发帖数: 1930 | 2 test2可能会有NRVO。应该是compiler-dependent。
http://msdn.microsoft.com/en-us/library/ms364057%28VS.80%29.aspx
i.
get
【在 b*******e 的大作中提到】 : How many constructor (including copy constructor) and destructors will be : called for test1 and test2? : Test1:3 constructors and destructors : Step-1 Default constructor will be called at Base a; : Step-2 Copy constructor will be called when passing a as formal parameter i. : e func(a). : Step-3 Copy constructor will be called for return object. : Step-4 Destructor will be called for actual parameter of func. : Step-5 Now this return obj will act as nameless obj in test1() and will get : destroy after line func
|
w**********8 发帖数: 121 | 3 Base() // base a
Base(const Base&)// func(a)
Base(const Base&)// base b = return value
~Base()// b in func
~Base()// a
~Base()//b
i.
get
【在 b*******e 的大作中提到】 : How many constructor (including copy constructor) and destructors will be : called for test1 and test2? : Test1:3 constructors and destructors : Step-1 Default constructor will be called at Base a; : Step-2 Copy constructor will be called when passing a as formal parameter i. : e func(a). : Step-3 Copy constructor will be called for return object. : Step-4 Destructor will be called for actual parameter of func. : Step-5 Now this return obj will act as nameless obj in test1() and will get : destroy after line func
|