From the course: C++ Best Practices for Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: RAII

Solution: RAII - C++ Tutorial

From the course: C++ Best Practices for Developers

Start my 1-month free trial

Solution: RAII

- [Instructor] So how'd it go? Were you able to complete this challenge? The clues for this challenge were that you should use DemoRaii as your model, and kind of keep in mind that a real resource still has a lot more work to do. Let's take a look at my solution. So as I said, we have here, here's the original DemoRaii, and here is the one that I built for the challenge. So this is DemoRaii2. It takes in an integer resource ID, it saves that ID out with the constructor and the destructor. It renders out the resource ID. Then I made a couple of additions to the Demo function. It now has two of these Demo twos mixed in, one before and one after the originals, and everything else should still be the same so let me go ahead and set this to True, and we'll save it. I will open it up in the command line, and do a clang++ -std=c++17 -Wall main.cpp And then do a ./a.out to execute it, and now we can see that we are entering the demo. We get our first one, and notice it has an ID number, then…

Contents