[工学]第十章运算符重载.pptVIP

  • 4
  • 0
  • 约1.25万字
  • 约 56页
  • 2018-02-18 发布于浙江
  • 举报
[工学]第十章运算符重载

* * * * * * class weight { public: weight(int v=0):value(v) {} //运算符前置自增 weight operator ++(); //运算符后置自增 weight operator ++(int); void print() { coutvalueendl; } private: int value; }; //前增量 weight weight::operator ++() { value++; return *this; } //后增量 weight weight::operator ++(int) { weight temp(*this); //操作数保存为临时对象 value++; //操作数加1 return temp; //返回没有加1的临时对象 } void main() { weight s1(1),s2; s1.print(); s2=s1++; s2.print(); s1.print(); (++s1)

文档评论(0)

1亿VIP精品文档

相关文档