A Question On Reference Type
First please look at the code
Code:
#include <iostream>
using namespace std;
class Test {
public:
Test() { cout << "Test" << endl; }
~Test() { cout << "~Test" << endl; }
};
int main()
{
const Test& t = Test();
//Test();
cout << "haha" << endl;
return 0;
}
and the output
If I comment out "const Test& t = Test();" and use "Test();" instead, the output will be
Don't you think it weird? Does the standard say that a temporary object's destruction will be deferred if it is referenced by an object of const reference type?