S
Samkit Jain
Code:
--------
#include <iostream>
using namespace std;
class Parent
{
public:
Parent()
{
cout << "Constructing " << this<< endl;
}
Parent(Parent& another)
{
cout << "Constructing (copy) " << this << endl;
}
~Parent()
{
cout << "Destructing " << this << endl;
}
void print()
{
cout << "Hello world" << endl;
}
};
int main()
{
Parent object;
({ object; }).print();
return 0;
}
Output:
-----------
Constructing 0xbfad96bf
Constructing (copy) 0xbfad96be
Hello world
Destructing 0xbfad96be
Destructing 0xbfad96bf
--------
#include <iostream>
using namespace std;
class Parent
{
public:
Parent()
{
cout << "Constructing " << this<< endl;
}
Parent(Parent& another)
{
cout << "Constructing (copy) " << this << endl;
}
~Parent()
{
cout << "Destructing " << this << endl;
}
void print()
{
cout << "Hello world" << endl;
}
};
int main()
{
Parent object;
({ object; }).print();
return 0;
}
Output:
-----------
Constructing 0xbfad96bf
Constructing (copy) 0xbfad96be
Hello world
Destructing 0xbfad96be
Destructing 0xbfad96bf