Re: Why is ((foo*)NULL)->bar(); undefined?
Thanks PredicateNormative that's getting close to what I'm looking for.
I'm interested in the standard rather than the semantics of the given code. I suppose my reason for asking could be better encapsulated in the following program:
Code:
#include <iostream>
class foo {
int bar() {
if (this == 0) return 0;
else return 1;
}
}
int main(int argC, char ** argV) {
std::cout << ((foo *) 0)->bar();
return 0;
}
It's clear that most compilers will allow this and most of them will simply print 0 and terminate with exit code 0. But the implication in other threads is that the result is undifined.
This supprised me (less so when I took in the intentional simularity between normal and virtual methods) and I'm looking for infomation about it.
Regards
Last edited by couling; January 20th, 2009 at 07:00 AM.
Reason: code correction
Signature
Please use: [ code ][/ code ] tags and reasonably correct tabbing. They really help us read your code
End Signature