一元运算符重载
参考https://www.imooc.com/video/9588
- 号
- 友元函数重载
略
- 成员函数重载
class A{ public: A& operator-(); private: int m_a; int m_b; } A& A::operator-();{ m_a = -m_a; m_b = -m_a; return *this; }
++号(前置与后置)
略
二元运算符重载
参考https://www.imooc.com/video/9591
+号
成员函数实现
class A{ public: A& operator+(const A & a); private: int m_a; int m_b; } A& A::operator+();{ A temp_a; temp_a.m_b = this->m_a+a.m_a; temp_a.m_b = this->m_a+a.m_b; return temp_a; }
友元函数实现
略
原文地址:https://www.cnblogs.com/geooeg/p/9650843.html
时间: 2024-10-07 20:12:50