Deallocate a stack object before execution gets out of the scope of the stack object?

115 views Asked by At

In C++, does RAII imply that a stack object (an object allocated on a stack, e.g. a local variable in a function) is deallocated only when execution gets out of the scope of the stack object?

What if I would like to deallocate a stack object a little bit before execution reaches the end of the scope of the stack object?

Thanks.

1

There are 1 answers

0
o11c On

It sounds like you want std::optional. It allows automatic resource management, but also allows a "deallocated" state.