operator== for struct
Hi! I've a problem to define the operator == for the follow struct:
1 2 3 4 5 6 7 8 9 10 11
|
struct t_time
{
/**
* from 0 to 59.
*/
public: byte min;
/**
* from 0 to 23.
*/
public: byte ora;
};
|
I've implemented the method as
1 2 3 4 5
|
bool RadioSveglia::t_time::operator==(const RadioSveglia::t_time& t1) {
if((t1.min==this.min)&&(t1.ora==this.ora))
return true;
return false;
}
|
but the compiler shows the error:
Error[Pe153]: expression must have class type C:\Users\Ivano\Desktop\src\t_time.cpp 6
|
Help me!!! Thank you!
this is a pointer, not a reference. It's also not necessary to explicitly use this. It can be shortened to:
1 2 3
|
bool RadioSveglia::t_time::operator==(const RadioSveglia::t_time& t1) {
return min==t1.min && ora==t1.ora;
}
|
Topic archived. No new replies allowed.