niusouti.com

( 14 )将前缀运算符 “ -- ” 重载为非成员函数,下列原型中,能正确用于类中说明的是A ) Decr& operator --(int);B ) Decr operator --( Decr&,int);C ) friend Decr& operator --(Decr&);D ) frlend Decr operator --(Decr&,int);

题目

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

A ) Decr& operator --(int);

B ) Decr operator --( Decr&,int);

C ) friend Decr& operator --(Decr&);

D ) frlend Decr operator --(Decr&,int);


相似考题
更多“( 14 )将前缀运算符 “ -- ” 重载为非成员函数,下列原型中,能正确用于类中说明的是A ) Decr& ”相关问题
  • 第1题:

    下列关于运算符函数的描述中,错误的是( )。

    A.运算符函数的名称总是以operator为前缀

    B.运算符函数的参数可以是对象

    C.运算符函数只能定义为类的成员函数

    D.在表达式中使用重载的运算符相当予调用运算符重载函数


    正确答案:C
    运算符函数可以定义为类的友元函数所以C选项错误。

  • 第2题:

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

    A.Deer&operator一一{int};

    B.Decroperator一一(Decr&,int);

    C.friendDeer&cperator一一(Deer&);

    D.friendDeeroperacor一一(Deer&,int);


    正确答案:C
    C。【解析】把“--”运算符重载为非成员(友元)函数格式:“friend<返回类型>operator--”是前缀的格式;friend<返回类型>operator--(int)是后缀的格式。当然也可以有参数如题中C选项所示。

  • 第3题:

    定义一个复数类complex, 重载运算符 “+”,使之能用于复数的加法运算,将运算符函数重载为成员函数;重载运算符 “-”,使之能用于复数的减法运算,将运算符函数重载为友元函数。编写主函数,测试运算符重载。


    friend complex& operator--(complex&) friend complex& operator--(complex&) 解析:本题考核运算符重载的定义。程序要填入的是运算符函数operator--在类complex中的声明,运算符“--”是作为友元函数重载的。根据题目给出的条件,易得到答案。

  • 第4题:

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

    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。

  • 第5题:

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

    A.DeCr&operator--(int);

    B.DeCr operator--(DeCr&,int);

    C.friend DeCr&operator--(DeCr&);

    D.friend DeCr operator--(DeCr&,int);


    正确答案:D
    非成员函数重载用友元函数的形式实现,“--”运算符重载分为前置和后置两种重载方式。用友元函数来实现“--”运算符的重载时,前置“--”运算符的重载的一般格式为:friendoperator--(ClassName&);后置++运算符的重载的一般格式为:friendoperator--(ClassName&,int)。所以答案为D。