0
点赞
收藏
分享

微信扫一扫

前置递减和后置递减重载

程序小小黑 2022-02-23 阅读 54
#include<iostream>
using namespace std;

class myinteger
{
public:

myinteger& operator--()
{
this->m_a--;
return *this;
}
myinteger operator--(int)
{
myinteger temp = *this;
this->m_a--;
return temp;
}



int m_a;
};

ostream& operator<<(ostream& cout,myinteger p)
{
cout << p.m_a;
return cout;
}

void test01()
{

myinteger p;
p.m_a = 10;
cout << --(--p) << endl;
cout << (p--) << endl;
cout << p << endl;

}

int main() {

test01();


system("pause");
return 0;
}
举报

相关推荐

0 条评论