Possible Duplicate:
What will happen when I call a member function on a NULL object pointer?
class A {
public:
void foo() { cout << "Work";}
void bar() { this->foo(); }//new edit, works too!
};
class B {
private:
A *a; //never initialized
public:
A& getA() {
return *a;
}
};
void SomeFunction() {
B *b = new B();
B& bRef = *b;
bRef.getA().bar();//edited
delete b;
}
I called SomeFunction() without initializing "a" and it still prints "Work" correctly. I don't understand why, it should have bailed out with segmentation fault!