1. 一般来说,重载了算数操作符(以下称"独身形式"),那么也就要重载复合赋值操作符(以下称"复合形式").要确保操作符的复合形式例如(operator+=)和独身形式(例如operator+)行为相一致,基于前者实现后者是一个好方法.例如:

class Rational{
public:
    Rational operator+=(const Rational&);
   ...
}
Rational operator+(const T&lhs,const T&rhs){
    return T(lhs)+=rhs;
}
View Code

相关文章:

  • 2021-07-25
  • 2021-07-17
  • 2021-08-03
  • 2021-11-18
  • 2021-08-02
  • 2021-10-25
  • 2021-12-30
  • 2022-12-23
猜你喜欢
  • 2021-11-26
  • 2021-07-08
  • 2021-05-18
  • 2021-06-02
  • 2021-07-20
  • 2021-11-07
  • 2022-02-09
相关资源
相似解决方案