0
class A
{
public:
    void Test()
    {
      AfxMessageBox("Test Function");
    }
};

A* obj= new A();
delete obj;
obj= NULL;
obj->Test();

Here Test function called without any error, I am using Visual studio compiler. if member function not accessing any other member in a class, "this" pointer will not use at all? is this applicable for all compilers?

kTechSE
  • 1
  • 1
  • Although it's not documented anywhere (that I know of), the Microsoft compilers will let you get away with this. More than that, some of Microsoft's own library code (eg MFC's `CWnd::GetSafeHwnd()`) makes use of this "feature". Still better not to use it. – dlf Nov 18 '14 at 16:29

1 Answers1

10

This is undefined behavior. It may work, it may not work, it may cause other weird bugs.

Don't rely on undefined behavior.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • We can say undefined behavior, , but if this is working all the time without any error or crash, there should be some trick right?? that is what my doubt.. – kTechSE Nov 18 '14 at 16:55