I am trying to access the functions in a class using pointers allocating memory using 'new'. But I noticed a different behavior. Once, the object was deallocated using 'delete' and NULL referenced, it is still able to access the functions, but not the variables. When I try to do it, I receive Segmentation Fault. Can someone explain? Thanks in advance!
#include <iostream>
using namespace std;
class A
{
public:
int ba;
A()
{
ba=10;
}
void func1()
{
cout<<"func1 is called\n";
}
void func2()
{
cout<<"func2 is called\n";
}
};
int main()
{
A *ptr=new A();
ptr->func1();
cout<<ptr->ba;
delete ptr;
ptr=NULL;
ptr->func2();
//cout<<ptr->ba;
return 0;
}