class Test
{
public:
Test() { cout << "Constructor is executed\n"; }
~Test() { cout << "Destructor is executed\n"; }
friend void fun(Test t);
};
void fun(Test t)
{
Test();
t.~Test();
}
int main()
{
Test();
Test t;
fun(t);
return 0;
}
Output I got for the code is as follows:
**Constructor is executed** //This is when Test() is called
**Destructor is executed** //This is when Test() is called
**Constructor is executed** //This is when Test t is called
//In the fun function
**Constructor is executed** //This is when Test() is called
**Destructor is executed** //This is when Test() is called
**Destructor is executed** //This is when t.~Test() is called
**Destructor is executed** // Don't know where this destructor comes from!
**Destructor is executed** //This is when Test t is called
I am not able to trace where the second last "destructor is executed" belongs to...!!!