What is meant by Resource Acquisition is Initialization (RAII)?

前端 未结 8 1691
面向向阳花
面向向阳花 2020-11-21 04:23

What is meant by Resource Acquisition is Initialization (RAII)?

8条回答
  •  终归单人心
    2020-11-21 05:05

    The book C++ Programming with Design Patterns Revealed describes RAII as:

    1. Acquiring all resources
    2. Using resources
    3. Releasing resources

    Where

    • Resources are implemented as classes, and all pointers have class wrappers around them (making them smart pointers).

    • Resources are acquired by invoking their constructors and released implicitly (in reverse order of acquiring) by invoking their destructors.

提交回复
热议问题