C ++: Reload prefix operator and reload suffix operator (take ++ as an example)
C ++: Reload prefix operator and reload suffix operator (take ++ as an example)
By Serena
In C ++, how does one distinguish between the overloaded prefix operator and the overloaded suffix operator? It is not difficult to find that the overload suffix operator carries the form parameter int while the overload prefix operator does not. This parameter is only used to differentiate the two parameters and has no practical significance.
We know that a ++ and a are different, for example, c = a ++ and c = ++ a. The values of two c types are different. Because the former assigns a to variable c first and then auto-increment, while the latter assigns the result of auto-increment to variable c first.
Therefore, because of this subtle difference, the code for reloading these two operators is quite different. The modern code is as follows:
/// Main. cpp // time /// Created by apple on 16/2/21. // Copyright (c) 2016 apple. All rights reserved. // # include
Using namespace std; class Time {private: int minutes; int hours; public: Time () {minutes = 0; hours = 0;} Time (int h, int m) {minutes = m; hours = h;} void display () {cout <"H"
All of the above are my own opinions. You are welcome to give criticism and guidance. Let's discuss it together!