2 ms·
All of this complicates the program significantly, and greatly reduces the advantages of RAII. If you're not using the constructors for initialization, than you
by tsimionescu 4y ago
All of this complicates the program significantly, and greatly reduces the advantages of RAII. If you're not using the constructors for initialization, than your desturctors also have to handle the case where the objects didn't even attempt to acquire the resource they may represent, for example.
Also, how to handle a failure to release a resource is context dependent, you can't encode it in the type of the resource unless you create a different type for each call site.
- fluoridation 4y agoIf you really need to do something different at each release point then you can have do_something_special_on_deallocation_failure() notify the error to the release point by a number of different mechanisms. Yes, all of this makes the code more complicated. The point of these features is not to make the code simpler, but to make it more robust. Rust is also more complicated than C.
- germandiago 4y agoYes, without exceptions is more involved, but way easier than any C alternative doing couple-of-functions mstching for alloc/dealloc.