On Fri, 5 Mar 2004 15:50:45 +0100, "Jakob Bieling" <ne*****@gmy.net> wrote:
Hi,
I remember reading a document that advised to prefer 'operator void*'
over 'operator bool' or other way round, when I want to provide the ability
to use code like this:
test_class t;
while (t)
{
// do stuff
};
But I cannot remember why and which method was prefered.
Thanks for the help!
To quote from Eckel/Allison's "Thinking in C++ Volume Two: Practical
Programming" (the footnote on page 167):
"It is customary to use operator void *() in preference to operator bool()
because the implicit conversions from bool to int may cause surprises,
should you incorrectly place a stream in a context where an integer
conversion can be applied. The operator void*() function will only be
called implicitly in the body of a Boolean expression."
Leor Zolman
BD Software
le**@bdsoft.com www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at
www.bdsoft.com/tools/stlfilt.html