operator???

I am curious about "operator"

My book that i'm reading is saying
"bool operator==(struct A& val);"

What does it mean??
If you have any idea, plz explain it and also other operators
like "operator++, --, //..etc.".
Thanks.
You are overriding some of the basic operators that are defined for your own definition.
For instance, if you add two custom classes together, there is not a definite way to actually add them to get a desired result, so you may need to add two values inside the classes.

In the example you specified, defining operator==(struct A& val) will allow you to compare

the struct A to another struct A

So if we have a struct of A1 and A2, using the operator we define the way we compare A1==A2 (boolean comparison). Say we had an integer in each of these structs that we would compare in order to find if they were equal, since we may have something like a name in there as well, we can override the
bool operator==(struct A& val) to compare A1->myint == A2->myint instead, ut obfuscate the user from that comparison (they would view it like A1==A2).

We use this in things like sorting algorithms, like heap sorting. There are a variety of other applications but this will probably be the first one you will see on your ventures to learning C++.
Last edited on
Thank you mcrist!!!
Topic archived. No new replies allowed.