#include <iostream>
using namespace std;
class RMB
{
friend const RMB operator+(const RMB &L,const RMB &R);
friend const RMB operator-(const RMB &L,const RMB &R);
friend bool operator>(const RMB &L,const RMB &R);
friend RMB &operator--(RMB &O);
friend const RMB operator--(RMB &O,int);
private:
int yuan;
int jiao;
int fen;
static int count;
public:
RMB()
{
countnum();
cout << "RMB::无参构造函数" << endl;
}
RMB(int yuan,int jiao,int fen):yuan(yuan),jiao(jiao),fen(fen)
{
countnum();
cout << "RMB::有参构造函数" << endl;
}
~RMB()
{
countnum1();
cout << "RMB::析构函数" << endl;
}
void show()
{
cout << count << endl;
}
static void countnum()
{
count++;
}
static void countnum1()
{
count--;
}
};
const RMB operator+(const RMB &L,const RMB &R)
{
RMB temp;
temp.yuan=L.yuan+R.yuan;
return temp;
}
const RMB operator-(const RMB &L,const RMB &R)
{
RMB temp;
temp.yuan=L.yuan-R.yuan;
return temp;
}
bool operator>(const RMB &L,const RMB &R)
{
if(L.yuan>R.yuan)
{
return true;
}
else
{
return false;
}
}
RMB &operator--(RMB &O)
{
--O.yuan;
--O.jiao;
--O.fen;
return O;
}
const RMB operator--(RMB &O,int)
{
O.yuan--;
O.jiao--;
O.fen--;
return O;
}
int RMB::count=0;
int main()
{
RMB r;
r.show();
RMB r1(1,1,1);
r1.show();
RMB r2(2,2,2);
r2.show();
RMB *r3=new RMB;
r3->show();
delete r3;
r3->show();
r3=nullptr;
// cout << "Hello World!" << endl;
return 0;
}
08-11
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-11
169
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-02
474
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-29
2737
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)