
return value on operator overloading
Greetings all, I have a operator overloading member function.
It just compares two values. When the two values are compared shouldn''t a value be returned like "0" or "1" since it is a BOOL type? Thanks.
**************************************************************
#include
struct Point2d
{
float x;
float y;
bool operator<(const Point2d & p1);
};
bool Point2d::operator <(const Point2d &p1)
{return ((x < p1.x) && (y < p1.y));}
int main()
{
Point2d pt1 = {10.0f, 15.0f};
Point2d pt2 = {110.0f, 8.0f};
cout << "example... " << endl;
pt1 < pt2;
return 0;
}
***********************************************************
-----------------------------
"There are ones that say they can and there are those who actually do."
"...u can not learn programming in a class, you have to learn it on your own."

-----------------------------"There are ones that say they can and there are those who actually do.""...u can not learn programming in a class, you have to learn it on your own."
Yes ... the result returned will be either ''true'' or ''false'', which when cast to integers will be ''1'' and ''0'' respectively. When casting from anything TO a bool .. it is important to know that a 0 (or 0.0 floating point) becomes ''false'' and anything non-zero becomes ''true'' ... so if you say:
while(4*2)
it will run forever, but if you say
while(3*0)
it will not run.
while(4*2)
it will run forever, but if you say
while(3*0)
it will not run.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement