CodeTheRobot

C++ Intermediate · exercise 01

Object lifetime & RAII

Enable and disable a motor from a constructor and destructor so it can never leak.

C++ Intermediate lesson 01

Guided steps

  1. 1.Print 'motor enabled' in the constructor and 'motor disabled' in the destructor.
  2. 2.Create the guard inside a nested scope and print work in between.
  3. 3.The destructor runs when the scope ends, before the final line.

Your code

Your code is saved in this browser after every run and restored next time.