⑴ 编译运行程序的结果是:

x=10 y=20 x=11 y=21

⑵ 程序中前置运算符“++”采用的重载方式是成员函数重载。

⑶ 将重载函数“coord coord::operator ++()”中的“++x; ++y; ”改为:“++this->x; ++this->y ; ” 重新运行程序。

结果不变,仍为:

x=10 y=20 x=11 y=21

改为“++this->x; ++this->y ; ”与“++x; ++y; ”效果相同。

⑷ 将“main()”函数中的“++ob;”改为“ob.operator++( );”,重新运算程序。

结果仍为:

x=10 y=20 x=11 y=21

这是因为“ob.operator++( );”也是调用了成员函数重载“++”运算符的操作。

程序1exp_301cpp用成员函数重载前置运算符++#include iostreamhclass coord int xy; public coordint i=0int j=0;	void print;	coord operator ++;;coordcoordint iint jx=i;y=j;void coordprint cout x=x y=yendl;coord c

原文地址: https://www.cveoy.top/t/topic/cmPD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录