temporary Object and destructor

...
cout << "Using a constructor to reset an object\n";
stock1 = Stock("Nifty Foods",10 , 50.0);
cout << "Revised stock1: \n";
stock1.show();
cout << "Done\n";
...

输出结果:

Using a constructor to reset an object
Constructor using Nifty Foods called
Bye~, Nifty Foods!          //注意这里是析构了临时对象,临时对象是由于stock1 = Stock("Nifty Foods", 10, 50.0 );创建的。
Revised stock1:
Company: Nifty Foods Shares: 10
Share Price: $ 50.000 Total Worth: $500.00
Done

stock1 = Stock("Nifty Foods",10 , 50.0);
先创建了临时对象,将值赋予该临时对象,再将临时对象的值赋予stock1。
posted @ 2018-01-23 16:48  Bear_Guo  阅读(96)  评论(0编辑  收藏  举报