热门

最新

红包

立Flag

投票

同城

我的

发布
qq_54222555
qq_54222555
5 年前
trueqq_54222555

马上要考Access,那位大神帮帮忙

CSDN App 扫码分享
分享
1
1
打赏
  • 复制链接
  • 举报
下一条:
为什么运行不出结果代码,求大神解答#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;//再将自身做返回 } //重载后置++运算符 //void operator++(int) int代表占位参数,可以用于区分前置和后置递增 MyInteger operator++(int) { //先返回结果 MyInteger temp = *this; //后递增 m_Num++; //最后将记录的结果返回 return temp; }private: int m_Num;};//重载<<运算符ostream& operator<<(ostream &cout, MyInteger myint) { cout << myint.m_Num ; return cout;}void test01() { MyInteger myint; cout << ++(++myint) << endl; cout << myint << endl;}void test02() { MyInteger myint; cout << myint++ << endl; cout << myint << endl;}int main(){ test02; system("pause"); return 0; }
立即登录