English 中文(简体)
C2679: binary <<:无操作者发现有权利操作的类型 累进(或不存在可接受的换算)
原标题:error C2679: binary << : no operator found which takes a right-hand operand of type Rectangle (or there is no acceptable conversion)
  • 时间:2009-09-22 17:07:43
  •  标签:

I m需要书写功能,超载=操作器,以比较宽度、高度和颜色。 如果是平等的,我就需要回来。

这是我认为正确的守则,但保留给我错误:

错误C2679:双轨和带;< :没有运营商发现哪类操作正确。 累进(或不存在可接受的换算)

我先寻找答案,而几乎对3项数据进行比较,因为大多数实例是比较2项数据。

#include <iostream>
#include <string>
using namespace std;

class Rectangle
{
private:
    float width;
    float height;
    char colour;
public:
    Rectangle()
    {
        width=2;
        height=1;
        colour= Y ;
    }
    ~Rectangle(){}
    float getWidth() { return width; }
    float getHeight() { return height; }
    char getColour() { return colour; }

    Rectangle(float newWidth, float newHeight, char newColour)
    {
        width = newWidth;
        height = newHeight;
        colour = newColour;
    }

    char operator== (const Rectangle& p1){

        if ((width==p1.width) && (height==p1.height) && (colour==p1.colour))
            return  Y ;
        else
            return  N ;
    }
};

int main(int argc, char* argv[])
{
    Rectangle rectA;
    Rectangle rectB(1,2, R );
    Rectangle rectC(3,4, B );
    cout << "width and height of rectangle A is := " << rectA.getWidth() << ", " << rectA.getHeight() << endl;
    cout << "Are B and C equal? Ans: " << rectB==rectC << endl;


    return 0;
}
最佳回答

“设计;设计;”高于“=”。 您对母体的比较:

cout << "Are B and C equal? Ans: " << (rectB == rectC) << endl;
问题回答

你们需要一些家长:

cout << "Are B and C equal? Ans: " << (rectB==rectC) << endl;

该编码是操作人的首要问题;<代码><<正在适用于<代码>rectB。 <代码>=。





相关问题
热门标签