C++运算符重载
发布日期:2021-05-10 03:28:51 浏览次数:18 分类:精选文章

本文共 3643 字,大约阅读时间需要 12 分钟。

C++ ���������������������

���C++������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������


���������������������

������������������binary operators���������������+���������������-���������������*���������������/���������������������������������������������������������������������������������������������������������������������������������������������������������Obj1���Obj2������������������������������������������������������������������������������������������������������������������������

������������������

������������������������������������������������������������������������������������������������������������������+���������������������������������������������������������������������������������������������������������������������������������������������

���������

int operator+(const Obj1& o1, const Obj2& o2) {
return o1.num + o2.num;
}

���������������������������������������������������������������������������������������������

������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������this������������������������this���������������������������������������������������������������atic������������������

���������Obj1������operator+���������

Obj2& operator+(const Obj1& o1) {
o1.num += 10;
return *this;
}

���������this���������������������������Obj1���������������������������������������������������


���������������������

������������������unary operators������������������++������������������--������C++������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������

Obj2& operator++() {
this->num++;
return *this;
}

������������������������������������������������������������������

Obj2& operator+(int) {
this->num++;
return *this;
}

���������������������������������������������������������������


���������������������

���������������<<��� insertion operator������������������������������������������������������������������������������������������������

friend ostream& operator<< (ostream& out, const RMB& r) {
out << "���������������" << r.getMoney() << "������������������" << r.GetYuan() << endl;
return out;
}

������������������RMB���������������������������������������������������������������������������������


���������������������

���������������������������������������������������������������������������������������������������������RMB������������double���������������������������������������������������

double operator(double) {
return yuan + (jiao / 100.0);
}

������������������������������������RMB���������������double���������������������������������������������������


���������������������

���������������������������������������������������������������������������������������������������EN���������������������������������������RMB���������������������������������������������������������������������

EN& operator=(RMB& rmb) {
this->meiyuan = rmb.getMoney();
return *this;
}

���������������������������������������������������������������������


������������������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:js文件中的require以及import 等语句中的{ }的作用
下一篇:6、Vue 开发的注意事项

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月11日 19时02分11秒