Troubles Overloading "==" with my class and constant character

--
Last edited on
bool operator == (const char rightside)
You wrote an operator here that accepts a single const char.


w1 == "Apple"

"Apple" is not a single const char. For the purposes of this code, it's effectively a const char*

A const char is not the same as a const char*
Last edited on
--
Last edited on
opperand types are incompatible ("int" and "const char*")

Yeah. Line 16: landOn is an int.
rightside is a const char *. Two very different types.
The compiler error is telling you exactly what is wrong.


--
Last edited on
Why did you comment out line 13?
--
Last edited on
Well, line 13 would enable to compare the class with a string so that

if (w1 == "Apple")

works.
You seem to have a correspondence between the value of landOn (a number) and the type of plant (a word) that the Cspinner "has":
landOn plant
------------
   0   Apple
   1   Orange
   2   Cherry
   3   Banana
   4   Peach

When you write (for example):
w1 == "Cherry"
the comparison has to (apparently) test whether w1.landOn == 2

(Alternatively, get plant name based on current value of landOn and then compare that name to the other operand.)


How would you "map" between numbers and words so that you can compare?
Topic archived. No new replies allowed.