将前缀运算符“--”重载为非成员函数,下列原型中,能正确用于类中说明的是( )。

admin2021-02-22  32

问题 将前缀运算符“--”重载为非成员函数,下列原型中,能正确用于类中说明的是(    )。

选项 A、Decr&operator--{int);
B、Decr operator--(Decr&,int);
C、friend Decr&cperator--(Decr&);
D、friend Decr operacor--(Decr&,int);

答案C

解析 把“--”运算符重载为非成员(友元)函数格式:“friend<返回类型>operator--()”是前缀的格式;friend<返回类型>operator--(int)是后缀的格式。当然也可以有参数如题中C选项所示。
转载请注明原文地址:https://kaotiyun.com/show/0ofp777K
0

最新回复(0)