This C++ code works for my platform and compiler (Windows, GCC 4.7):
#include <stdio.h>
class A {
public:
/* ... */
int size() const
{
if ( this == NULL ) {
return 0;
}
return m_size;
}
private:
int m_size;
};
int main()
{
A* a = NULL;
printf( "%d\n", a->size() );
}
But is this code valid standard C++ and portable? Is it Ok for method to accept this == NULL?