Я работаю над домашним заданием:
Добавьте область из 2 кругов, используя перегруженный +
Добавьте область из2 прямоугольника с использованием перегруженного +
Сравните площадь круга и прямоугольника, чтобы увидеть, совпадают ли они с использованием перегруженного ==
Сравнитьплощадь круга и прямоугольника, чтобы увидеть, что больше, используя перегруженный>
До сих пор я завершил первые три. Я написал код для перегрузки больше, чем функция, но я все время получаю сообщение об ошибке - "no operator"> "соответствует этим операндам"
Я попытался изменить функцию оператора, чтобы она была функцией-членом прямоугольника классаи класс кружок. Я даже пытался изменить оператор> на другие операторы, но у меня все еще та же ошибка.
ShapesType.h selection-
friend bool operator==(const circleType&,
const rectangleType&);
//Overload the operator ==
friend bool operator>(const circleType&,
const rectangleType&);
//Overload the operator >
ShapesTypeImp.cpp selection-
bool operator== (const circleType& Circle,
const rectangleType& rectangle)
{
return Circle.area() == rectangle.area();
}
bool operator> (const circleType& Circle,
const rectangleType& rectangle)
{
return (Circle.area() > rectangle.area());
}
Main.cpp selection-
case 3:
cout << "Enter the radius of the circle: ";
cin >> radius;
while (cin.fail())
{
cin.clear();
cin.ignore(100, '\n');
cout << endl << "Not a valid input, enter a number: ";
cin >> radius;
}
cout << "Enter the height of the rectangle: ";
cin >> height;
while (cin.fail())
{
cin.clear();
cin.ignore(100,'\n');
cout << endl << "Not a valid input, enter a number: ";
cin >> height;
}
cout << "Enter the width of the rectangle: ";
cin >> width;
while (cin.fail())
{
cin.clear();
cin.ignore(100,'\n');
cout << endl << "Not a valid input, enter a number: ";
cin >> width;
}
circle.setRadius(radius);
rectangle.setDimensions(height, width);
cout << "The area of the circle is: " << circle.area() << endl;
cout << "The area of the rectangle is: " << rectangle.area() << endl;
if (circle == rectangle)
{
cout << "The area of the circle is equal to the area of the rectangle.";
}
else
cout << "The area of the circle is not equal to the area of the rectangle.";
cout << endl << endl;
break;
case 4:
cout << "Enter the radius of the circle: ";
cin >> radius;
while (cin.fail())
{
cin.clear();
cin.ignore(100, '\n');
cout << endl << "Not a valid input, enter a number: ";
cin >> radius;
}
cout << "Enter the height of the rectangle: ";
cin >> height;
while (cin.fail())
{
cin.clear();
cin.ignore(100, '\n');
cout << endl << "Not a valid input, enter a number: ";
cin >> height;
}
cout << "Enter the width of the rectangle: ";
cin >> width;
while (cin.fail())
{
cin.clear();
cin.ignore(100, '\n');
cout << endl << "Not a valid input, enter a number: ";
cin >> width;
}
circle.setRadius(radius);
rectangle.setDimensions(height, width);
cout << "The area of the circle is: " << circle.area() << endl;
cout << "The area of the rectangle is: " << rectangle.area() << endl;
if (circle > rectangle)
{
cout << "The area of the circle is greater than the area of the rectangle.";
}
else
cout << "The area of the rectangle is greater than the circle.";
cout << endl << endl;
break;
Я включил случай 3, потому что он работает, как и ожидалось. Случай 4, использующий практически идентичный код, выдает ошибку операнда. Кажется, что он пытается использовать std> вместо перегруженного>. Я не уверен, как это исправить, и любая помощь или понимание будут с благодарностью.
Прикрепленное изображение ошибки: