[C++] 纯文本查看 复制代码 #include <iostream>
namespace wind_test
{
class CMyInteger
{
public:
friend std::ostream &operator <<(std::ostream &out, const CMyInteger &obj);
public:
CMyInteger &operator ++()
{
this->m_num ++;
return *this;
}
CMyInteger operator ++(int)
{
CMyInteger tmp = *this;
this->m_num ++;
return tmp;
}
private:
int m_num{};
};
std::ostream &operator <<(std::ostream &out, const CMyInteger &obj)
{
return out << obj.m_num;
}
}
int main(void)
{
wind_test::CMyInteger m;
m ++;
++ m;
std::cout << m << std::endl;
std::cout << m ++ << std::endl;
return 0;
} |