1: when using a common function
Front ++: the parameter is a non-read-only reference type, and the return type is a non-read-only reference. The value must be calculated first and then
Post ++: the parameter is a non-read-only reference type and an int type (INT type does not work to distinguish between front and back ). The returned value is a common class. The value is first taken before calculation (an unknown object can be used)
# Include <iostream> # Include <Stdio. h> # Include < String > Using Namespace STD; Class A { Int N; Public : ( Int N): n (n ){} Int Get (); Friend & Operator ++ (& A); friend Operator ++ (A &, Int B) ;}; & Operator ++ (& A) {A. N ++ ; Return A;} Operator ++ (A &, Int B ){ Return A (A. N ++ );} Int A :: Get (){ Return N ;} Int Main () { = 5 ;( ++ (++ A) ++ ; Cout <. Get () < Endl; A B = A ++ ; Cout <B. Get () < " " <. Get () < Endl; System ( " Pause " ); Return 0 ;}
2: function member:
Front ++: No parameter (there is an implicit this pointer pointing to the current object). The returned type is a non-read-only reference. The value must be calculated first and then
Rear ++: an int type (INT type does not have any function, used to distinguish between front and back) and another (implicit this type, pointing to the current object ). The returned value is a common class. The value is first taken before calculation (an unknown object can be used)
# Include <iostream> # Include <Stdio. h> # Include < String > Using Namespace STD; Class A { Int N; Public : ( Int N): n (n ){} Int Get (); & Operator ++ (); Operator ++ ( Int B) ;}; & ::Operator ++ () {N ++ ; Return * This ;} :: Operator ++ ( Int B ){ Return A (n ++ );} Int A :: Get (){ Return N ;} Int Main () { = 5 ;( ++ (++ A) ++ ; Cout <. Get () < Endl; A B = A ++ ; Cout <B. Get () < " " <. Get () <Endl; System ( " Pause " ); Return 0 ;}
3: Write with youyuan:
# Include <iostream> # Include <Stdio. h> # Include < String > Using Namespace STD; Class A { Int N; Public : ( Int N): n (n) {} friend Int Get (A); & Operator ++ (); Operator ++ ( Int B) ;}; & :: Operator ++ () {N ++ ; Return * This ;} :: Operator ++ ( Int B ){ Return A (n ++ );} Int Get (){ Return A. N ;} Int Main () { = 5 ;( ++ (++ A) ++ ; Cout < Get (A) < Endl; A B = A ++ ; Cout < Get (B) < " " < Get (A) <Endl; System ( " Pause " ); Return 0 ;}