Result of Running ...
Enter Temp()
Enter copy Temp(const Temp& rhs)
Enter ~Temp()
Enter copy Temp(const Temp& rhs)
Enter ~Temp()
Enter ~Temp()
Questions:
1. I thought Temp e2 = e1 would call operator =, but actually called copy constructor. I am not sure why and I was wondering what would be the difference between Temp e2 = e1; and Temp e2(e1); call?
2. Is there any way that we can force Temp e1 object to be cleared/deleted/free before the end block "}" of main() is reached?
1) It would never call operator=. Just like '*' is used for both multiplication and dereferencing, the character '=' is used for more than one purpose.
The difference between the various forms of copy construction is about the permissible implicit conversions: Temp e2(e1);allows everything, Temp e2 = e1; doesn't call explicit constructors, Temp e2{e1}; prohibits narrowing conversions. But in your case, e1 has the type Temp. No conversions are needed, and there is no difference.
2) Yes, you can call destructors directly. However, the end of main() will call e1's destructor again and that's an error (unless you placement-new e1 back into existence before letting main() end.. but you don't want to go there)