1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream> using namespace std; struct B{ int b; ~B(){cout <<"destruct B" << endl;} }; B func(){ B b; b.b = 1; return b; } int main(){ const B& instance = (const B&)func(); cout <<instance.b<<endl; return 0; }
1 2 3
destruct B destruct B 1