📜  C ++ |运算符重载|问题5

📅  最后修改于: 2021-06-01 02:34:38             🧑  作者: Mango

重载后缀和前缀运算符之间的C++编译器有何区别?
(A) C++不允许两个运算符都在一个类中重载
(B)后缀++具有伪参数
(C)前缀++具有虚拟参数
(D)将前缀++用作全局函数,将后缀作为成员函数。答案: (B)
说明:请参见以下示例:

class Complex
{
private:
    int real;
    int imag;
public:
    Complex(int r, int i)  {  real = r;   imag = i; }
    Complex operator ++(int);
    Complex & operator ++();
};

Complex &Complex::operator ++()
{
    real++; imag++;
    return *this;
}

Complex Complex::operator ++(int i)
{
    Complex c1(real, imag);
    real++; imag++;
    return c1;
}

int main()
{
    Complex c1(10, 15);
    c1++; 
    ++c1;
    return 0;
}

这个问题的测验