I have written the following code.
Code: Select all
#..........
class test
{ public:
static unsigned char temp;
test()
{ temp++;
}
~test()
{ temp--;
}
};
test f(test t)
{ return t;
}
unsigned char test::temp=0;
int main()
{ class test o1;
class test o2=f(o1);
}
class test o1-- temp=1 as object is created.
class test o2=f(o1) temp=0xff as destructor is called two times.
I do not understand, why destructor is called two times.
kindly tell me, why this program behaves like this, according to my knowledge, output should be
during
class test o2=f(o1) temp=0;
kindly tell me why this difference comes.
Thanks & Regards