Will the following give a compilation error?
delete cout;
delete cin;
The answer is : No.
It is a flaw in the implementation of strea
If I can give my 2 cents, I think the standard library "flawed" a bit, with all the good intentions.
The operator void*()
had been introduced to allow code like
while(stream)
or if(!stream)
or while(stream && ...)
, without giving an implicit access to integer arithmetic (that operator bool
whould have given).
In fact, this disable integer arithmetic, but gives access to pointer features (like delete ...).
Now, in C++0x, an explicit oeprator bool()
had been introduced. It doesn't implicitly give access to whatever feature, since it requires an implicit conversion. But ... wait a bit: 'while(bool(stream))' or even while(static_cast
are so wordy...
Operator ! is explicit, and
'while(!!stream)' looks so effective that I even wonder why not accept this as a paradigm:
If I want something to be explicitly converted into bool, I just provide an operator!()
and give to !
the memaning of "is not valid" and of !!
as "is valid".
Much safer then an implicit conversion and not uselessly wordy: after all !
exist from ever!