class fu
{
public:
int pub;
fu() { pub = 1; }
~fu() {
std::cout << pub << "end"<<std::endl;
}
};
fu& fub() {
fu a;
fu& re = a;
return a;
}
int main() {
std::cout << ++fub().pub;
}
output : 1 end \n 2
I expected that the reference would make an error because the variable in the function has been terminated. However, the destructor was called in and main function worked. What does the reference point to?