#include<iostream>
using namespace std;
class myinteger {
friend ostream& operator<<(ostream& cout, myinteger& myint);
public:
myinteger() {
m_num = 0;
}
myinteger& operator++() {
m_num++;
return *this;
}
private:
int m_num;
};
ostream& operator<<(ostream& cout, myinteger& myint) {
cout << myint.m_num;
return cout;
}
int main() {
myinteger myint;
cout << ++myint << endl;//myint.operator++()
}
这里的myinteger的对象myint调用operator不是myint.operator++()这样的吗,那简化之后应该是myint++吧,为什么是++myint呢?