May STL iterator methods throw an exception

后端 未结 4 759
抹茶落季
抹茶落季 2020-12-09 17:07

Destructors may not throw exceptions (so stack unwinding can complete during exception handling), and must deallocate any resources allocated to the object (so no resources

4条回答
  •  遥遥无期
    2020-12-09 17:16

    The destructor would therefore use the following iterator-related methods

    No it would not. The destructor of that object would just call the destructor of the container, which would in turn be guaranteed to not throw an exception.

    If you use RAII correctly, you will almost never run into a scenario where you have to explicitly release resources. This could be achieved by have the container store shared_ptr or unique_ptr, or by using something like Boost.Pointer Container.

提交回复
热议问题