ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
the operator bool() is a conversion operator, it converts it's return value to type bool? the if-statement takes a relational argument, and when i pass my object to it...the compiler automatically sees that it can 'convert' it into bool via that operator bool(), so it is now accepted as if the object itself were == to a relational value (true,false), based on what it had returned (actually i have it return 'true' or 'false' depending on a 'FILE * stream' being NULL or not) ..now since i'm am actually returning a 'legal' bool value from the start , there should be no foul play that would be involved in an implicit cast (or no?)
Thats right, although I'm not familiar with the term relational being used to describe boolean expresstions.. I'd describe the 'if' statement as taking a boolean expression (ie one that is either true or false).
operator bool() is a conversion operator, I'll pinch/paraphrase some text from "The ANSI/ISO C++ Profession Programmer's Handbook":
Quote:
A conversion operator, can be thought of as a user defined typecasting operator; it converts its object to a different type in contexts that require that specific type.
Conversion operators differ from ordinary overloaded operators in two way. First, a conversion operator does not have a return value (not even void). The return value is deduced from the operators name. Secondly, a conversion operator takes no arguments.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.