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

admin2021-02-22  17

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

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

答案D

解析 非成员函数重载用友元函数的形式实现,"--"运算符重载分为前置和后置两种重载方式。用友元函数来实现"--"运算符的重载时,前置"--"运算符的重载的一般格式为:friend operator -- (ClassName & );后置++运算符的重载的一般格式为:friend operator--(ClassName &,int)。所以答案为D。
转载请注明原文地址:https://kaotiyun.com/show/Ubfp777K
0

最新回复(0)