本帖最后由 zds212 于 2021-5-7 22:32 编辑
[C++] 纯文本查看 复制代码 #include <iostream>
using namespace std;
class mint
{
public:
mint(int num)
{
number = new int(num);
}
mint& operator=(mint &p)
{
if (number != NULL)
{
delete number;
number = NULL;
}
number = new int(*p.number);
return *this;
}
int *number;
};
ostream& operator<<(ostream& cout,mint p)
{
cout << *p.number ;
return cout;
}
void text01()
{
mint p1(5);
mint p2(6);
mint p3 = p2=p1;
cout << p3 <<" "<<p2<<" "<<p1<<endl;
}
int main()
{
text01();
system("pause");
return 0;
} |