Technical Discussion :: C++
Home > Technical Interview Q&A > C++ > Discussion
77 / 187
How to use delete operator in destructor?
Answer:
Whenever new is used to allocate memory in the constructors. We should use delete to free that memory. For example, the destructor for the matrix class discussed above may; be defined as follows
Matrix :: ~matrix( )
{
for(int i=0;i
delete p;
}
Asked In ::
Priyanka Singh
23 Feb, 2019 5:07 AM
Whenever new is used to allocate memory in the constructors. We should use delete to free that memory. For example, the destructor for the matrix class discussed above may; be defined as follows
Matrix :: ~matrix( )
{
for(int i=0;i
delete p[i];
delete p;
}
Matrix :: ~matrix( )
{
for(int i=0;i
delete p;
}