You call the destructor. It’s simply not automatically done for you with the concept of going out of scope.
Back when C++ was simply a text pre-processor for C, you could see these normal function calls. You can still see them in the un-optimized disassembly. There’s nothing magical about a destructor other than it being inserted automatically.
The point of RAII is that a resource is allocated and freed in the same scope.
You can free it with an explicit call to a destructor, an implicit call, or with memory allocated on the stack, just wait for the stack frame to be exited.
Classes are just pretentious structs.
How do you get destructor behavior in C?
You call the destructor. It’s simply not automatically done for you with the concept of going out of scope.
Back when C++ was simply a text pre-processor for C, you could see these normal function calls. You can still see them in the un-optimized disassembly. There’s nothing magical about a destructor other than it being inserted automatically.
Aka the entire point of RAII
The point of RAII is that a resource is allocated and freed in the same scope.
You can free it with an explicit call to a destructor, an implicit call, or with memory allocated on the stack, just wait for the stack frame to be exited.