我是C ++编程语言的初学者,试图学习运算符重载。试图了解以下代码段,
#include <iostream>
using namespace std;
class Time {
private:
int hours; // 0 to 23
int minutes; // 0 to 59
public:
Time(int h, int m) {
hours = h;
minutes = m;
}
void displayTime() {
cout << "H: " << hours << " M:" << minutes <<endl;
}
Time operator++( int) {
Time T(hours, minutes);
++minutes;
if(minutes >= 60) {
++hours;
minutes -= 60;
}
cout<<"post-increment"<<endl;
return T;
}
};
int main()
{
Time T2(10,40);
Time T3 = T2++;; // increment T2
T2.displayTime();
T3.displayTime(); // display T2
return 0;
}
谁能告诉我
我经历了link,但没有得到我问题的具体答案。