|
发表于 2021-6-25 08:51:14
|
显示全部楼层
vs2019,,运行通过,,加个 const
- #include <iostream>
- using namespace std;
- class myInteger
- {
- friend ostream& operator<<(ostream& cout, const myInteger& Inte);
- public:
- myInteger() {
- m_int = 0;
- }
- //前置++运算符重载
- myInteger& operator++() {
- m_int++;
- return *this;
- }
- //后置++运算符重载
- myInteger operator++(int) {
- myInteger temp = *this;
- m_int++;
- return temp;
- }
- private:
- int m_int;
- };
- ostream& operator<<(ostream& cout, const myInteger& inte) {
- cout << inte.m_int;
- return cout;
- }
- void test01() {
- myInteger Inte;
- cout << ++Inte << endl;
- cout << ++(++Inte) << endl;
- cout << Inte << endl;
- cout << Inte++ << endl;
- cout << Inte << endl;
- cout << (Inte++)++ << endl;
- }
- int main() {
- test01();
- system("pause");
- return 0;
- }
复制代码 |
评分
-
查看全部评分
|