Re: Virtual function pointers == NULL. Allowed?
Daniel T. ha scritto:
#include <cassert>
class Foo {
public:
virtual void fnA() = 0;
virtual void fnB() = 0;
};
int main() {
assert( &Foo::fnB );
assert( &Foo::fnA );
}
What does the standard say about the above code? In the compiler I'm
using now, the first assert will not fire, but the second one will. I
expected that neither assert would fire...
Then your compiler is very buggy. According to 4.12:
"[... a] null member pointer value is converted to false; any other
value is converted to true."
The null member pointer value is defined in 4.11 and is a value which is
"distinguishable from any pointer to member not created from a null
pointer constant".
So neither &Foo::fnA nor &Foo::fnB are null member pointer values and
therefore none of them, when converted to bool, shall evaluate to false.
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]