In this case, I am getting some issue. Please find below code snippet
Code: Select all
class Test
{
public:
uint8_t* m_ptr;
Test();
~Test();
void show_element();
};
Test::Test()
{
m_ptr = new uint8_t[10];
m_ptr[0] = 10;
printf("Inside Test() \n\r");
}
Test::~Test()
{
if(nullptr != m_ptr)
{
delete[] m_ptr;
m_ptr = nullptr;
}
}
void Test::show_element()
{
printf("m_ptr[0] = %d \n\r", m_ptr[0]);
}
void main()
{
Test* tptr = new Test;
tptr->show_element();
tptr->~Test();
delete tptr;
}
Basically last line is not executing.
delete[] m_ptr; // This is executing.
m_ptr = nullptr; // This is not executing. Maybe due to optimization.
// And after this call is returning from destructor.
So, can anyone please suggest how can I make it execute?