Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to call a function inside a destructor in C++ [duplicate]

Tags:

c++

Is it a good practice to call a function inside a destructor which does some memory allocations internally. Because this is giving me access violations and other issues, For suppose

~Example(){
    Stop();
}

Here in this function Stop() does various things and also calls various other functions? Is it a good practice. Can anyone help with this?

like image 737
user1767288 Avatar asked Feb 17 '23 05:02

user1767288


1 Answers

There is nothing wrong in calling functions inside destructor the only important point to consider is that there should be no uncaught exceptions emitting from a destructor.

So, As long as you catch all the exceptions thrown from functions called within the destructor inside the desructor, You are safe.

like image 144
Alok Save Avatar answered May 01 '23 23:05

Alok Save