Hi,
I am trying to write the code which will create the class object on the heap using the "new" operator and trying to free it using "delete" operator. The code is as follows.
/*****************************************/
class CTest {
public:
int i;
};
void main(void)
{
CTest * ct1 = new CTest;
CTest *ct2 = ct1;
delete ct1;
ct1 = NULL;
ct2->i = 900;
cout << "i= " << ct2->i << endl;
return;
}
/***************************************/
As per my understanding, i should get the access violation after the delete statement. But the code is running properly. Can you help me out in understanding the concept ?
Thanks in advance
Sanjay
I am trying to write the code which will create the class object on the heap using the "new" operator and trying to free it using "delete" operator. The code is as follows.
/*****************************************/
class CTest {
public:
int i;
};
void main(void)
{
CTest * ct1 = new CTest;
CTest *ct2 = ct1;
delete ct1;
ct1 = NULL;
ct2->i = 900;
cout << "i= " << ct2->i << endl;
return;
}
/***************************************/
As per my understanding, i should get the access violation after the delete statement. But the code is running properly. Can you help me out in understanding the concept ?
Thanks in advance
Sanjay