Take the 2-minute tour ×  Here is the code which confuses me:
#include <iostream> using namespace std;  class B {     B() {
cout << "constructor\n";     B(const B& rhs) {         cout <<
"copy ctor\n";     B & operator=(const B & rhs) {         cout
<< "assignment\n";     ~B() {         cout << "destructed\n";
B(int i) : data(i) {         cout << "constructed by parameter "
<< data << endl;      int data;  B play(B b)     return b;  int
main(int argc, char *argv[]) #if 1     B t1;     t1 =  play(5);
#if 0     B t1 = play(5);      return 0;  Environment is g++
4.6.0 on Fedora 15. The first code fragment output is as
follows:  constructed by parameter 5 copy ctor  And the second
fragment code output is:  constructed by parameter 5 copy ctor
Why are are three destructors are called in the first example,
while in the second it is only two?  share|improve this question
How many constructors were you expecting to see? If not enough
try compiling with -fno-elide-constructors and gcc won't
eliminate so