Here is Example..!! Can you explain how it works? why Destruct just one time?
#include <iostream>
using namespace std;
class A {
public:
    A() {
        cout << "A's Construct" << endl;
    }
    ~A() {
        cout << "A's Destructr" << endl;
    }
    A(const A& obj) {
        cout << "A's Copy Constructor" << endl;
    }
};
A fun() {
    A obj;
    cout << "Fun" << endl;
    return obj;
}
int main() {
    A obj = fun();
    cout << "End" << endl;
    return 0;
}
and when I run above program output is:
A's Construct
Fun
End
A's Destructor
But When I remove Copy Constructor from the above code then Output is:
A's Construct
Fun
A's Destructor
End
A's Destructr
I'm expecting 2 Destructor for function's obj and main's obj and 1 time Copy Constructor for A obj=fun(); and one time Simple constructor for Function's object.
Expecting Output:
A's Construct
Fun
A's Destructor
A's Copy Constructor
End
A's Destructr
Can you explain the difference? I know there is Move semantics or RVO But I'm confused how they performing in this code?
Compiled in Visual Studio 2015.
 
     
    