Tim Schumacher wrote:
> !object you can do with overloading operators, for just checking object
> I didnt figured out yet. This is a small Program which I tried and
> seemed to work:
I think I found it :)
----
/**
* @brief The quick-and-easy status check.
*
* This allows you to write constructs such as
* "if (!a_stream) ..." and "while (a_stream) ..."
*/
operator void*() const
{ return this->fail() ? 0 : const_cast<basic_ios*>(this); }
bool
operator!() const
{ return this->fail(); }
----
Seems I was right about the conversion, but they simplified the whole=20
thing with converting it to void*, as it will also be used in a bool=20
context (one less operator overload to write).
I still wonder, what if I write a bool conversion operator only. Then I=20
wouldn't even need operator!, because bool conversion is made first, and=20
"not" (operator!) is used afterwards for the converted bool value.
It's late now. I'll write some test-progs tomorrow.
--
Greetings,
Bal=E1zs
|