有人可以向我解释为什么我的重载 ++ (之前版本)没有更新该值吗?片段是这样的:
circle circle:: operator++()
{
Area = Area * 2.0;
return *this;
}
/////////////////////////////
int main()
{
class circle c1(4, 1, -1), c2(12, 4, 6);
c1.output();
c1++;
c1.output();
system("pause");
return 0;
}
这是因为你重载了前缀并调用了后缀。你需要打电话++c1;
。使用c1++;
您还需要重载后缀:
circle operator++ ( int );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)