Originally posted by elad
I thought bool was a type, not an operator????? How can you overload a type?
bool won;//bool used as a type
public:
test ( bool init )//bool used as a type
: won ( init )
{}
operator bool()//bool used as an operator???
I'll have to go back and review syntax of conversion operators.........again. Sighhhhhhhh
You are basically telling the compiler "If you see this object out of place call this if it fits.".
ie:
Code:
class person { public:
person(int years)
:age(years)
{ /* */ }
operator int ( ) {
return age;
}
private:
int age;
};
person Mike(27);
person Peter(55);
if(Mike > Peter)
cout << "Mike is older, at the age of " << Mike;
if(Mike < Peter)
cout << "Peter is older, at the age of " << Peter;
else
cout << "Peter and Mike are the same age";
getch();
return 0;
}