I wrote a simple code like this:
class Test
{
public:
    Test()
    {
        cout << "Constructor called." << endl;
    }
    ~Test()
    {
        cout << "Destructor called." << endl;
    }
    Test(const Test& test)
    {
        cout << "Copy constructor called." << endl;
    }
    void Show() const
    {
        cout << "Show something..." << endl;
    }
};
Test Create()
{
    return Test();
}
int main()
{
    Create().Show();
}
The output for this code are:
Constructor called.
Show something...
Destructor called.
But when I modified the function Create() like this:
Test Create()
{
    Test test;
    return test;
}
The output are:
Constructor called.
Copy constructor called.
Destructor called.
Show something...
Destructor called.
Why the anonymous object do not call the copy constructor and destructor?Please help me, thanks.
 
     
     
    