RAII Resource Guard

Medium C++ Memory
Solve this problem

Implement a C++ RAII guard class that acquires a resource in constructor and releases it in destructor.

Constraints

  • Use constructor/destructor.
  • Resource simulated via bool flag.
  • No manual release function.
  • Prevent copying.
Starter codeC++
1class Guard {2private:3    bool *res;4public:5    Guard(bool *r);6    ~Guard();7};