<分区>
Possible Duplicate:
What will happen when I call a member function on a NULL object pointer?
好吧,我认为这段代码和程序输出可以 self 解释:
#include <iostream>
#include <string>
using namespace std;
class Test
{
public:
void Not_Static(string args)
{
cout << args << endl;
}
};
int main()
{
Test* Not_An_instance = nullptr;
Not_An_instance->Not_Static("Non-static function called with no object?");
cin.ignore();
return 0;
}
程序输出:
Non-static function called with no object?
为什么这是可能的?