选择题
8.
将前缀运算符“--”重载为非成员函数,下列原型中能正确用于类中说明的是______。
A、
Decr&operator--(int);
B、
Decr operator--(Decr&,int);
C、
friend Decr&operator--(Decr&);
D、
friend Decr operator--(Decr&,int);
【正确答案】
D
【答案解析】
非成员函数重载用友元函数的形式实现,“--”运算符重载分为前置和后置两种重载方式。用友元函数来实现“--”运算符的重载时,前置“--”运算符的重载的一般格式为:friend<type>operator--(ClassName&);后置++运算符的重载的一般格式为:friend<type>operator--(ClassName&,int)。所以答案为D。
提交答案
关闭