Why do I keep getting a conversion error: char op; cout << "Enter the operator: "; cin >> op; switch (op) { case '+': Square3 = Square1 + Square2; cout << Square3; break; case '-': Square3 = Square1 - Square2; cout << Square3; break; case '*': Square3 = Square1 * Square2; cout << Square3; break; default: cout << "No a valid operator"; }
what error do u get?
I get it when I try to cout << Square3 in the switch structure
This is what someone else told me The operator << hasn't been defined for a Square object Either define it within the Square class, or cout whatever specific things about Square3 you actually intended
@mathmate
@Zale101
@Elsa213
@rishavraj he's good at computer science :)
@Gokuporter Your post does not mention on which line and which method the error occurred. If it is on one of the cout lines, it would possibly be because you're outputting an object that cout does not know how to convert. Also, the overloaded operators work with the sides of the objects, not the area. I would think it is more intuitive when you add two squares, you would sum the areas. But that's a personal choice. The overloaded * and / will give dimensional problems because side*side gives area units, and side/side will give a pure number, but they both got assigned to the variable "side".
hj
f
Join our real-time social learning platform and learn together with your friends!