#include <iostream>
using namespace std;
struct Node{
int u;
Node(int uu = 0):u(uu){
cout << "create" << endl;
}
~Node(){
u = 0;
cout << "delete/n";
}
Node(const Node &no){
cout << "copy/n";
u = no.u;
}
Node operator + (const Node &no) const{
cout << "+/n";
Node tmp;
tmp.u = u+no.u;
cout << "return tmp/n";
return tmp;
}
Node& operator ++ (){
cout << "pre/n";
++u;
return *this;
}
const Node operator ++ (int){
Node tmp = *this;
++u;
return tmp;
}
};
Node& f(Node &no){
no.u += 1;
return no;
}
//多层函数引用时编译器检查不出,不会有警告
Node& ff(){
Node n(10);
cout << "ff/n";
return f(n);//函数调用完即析构,但却仍被引用
}
int main(){
Node &t = ff();
cout << t.u << endl;
return 0;
}