Is it valid to call non-static methods using null pointer? I have a below example which works perfectly fine.
#include <iostream>
class foo
{
public:
void printMessage()
{
std::cout<<"Hello World";
}
};
int main()
{
foo *a = NULL;
a->printMessage();
return 0;
}
I also wanted to know, How it works? and, is it an example of undefined behaviour?