Resource Acquisition Is Initialization, or RAII, is a technique which can free your code from the dangers of the new/delete dependencies. It is probably one of the most important techniques for C++ developers to learn and master. Troy walks through it in this video.
- [Instructor] Resource Acquisition Is Initialization, RAII.…It's about writing safer C++ code.…The destructors of stack objects are always called.…Stack objects are destroyed…in reverse order of their creation.…So, any critical resources should be created on the stack…and they should be written to destroy themselves properly.…Let's check out some code.…What we have here is just a basic demo of RAII principles.…
So we have a class called DemoRaii.…It is marked explicit because it takes a single resource…and we don't want it to accidentally…try to convert something implicitly.…And in this case,…the single thing that it takes in is a string…and we're just going to destroy that string…so that we can identify these later.…The constructor doesn't do anything else…other than print out the class name…and then the name of its string.…And then in the destructor, the same thing is going on.…It's printing out the class name…and the name of its identifier string.…
So we have a method called demo and inside this method,…it just prints out a message saying…
- Major new C++ features
- Turning on modern C++
- Letting the compiler help
- Using the new features correctly
- Using auto type deduction
- Using lambdas
- Range-based for loops
- How C++ and the Standard Template Library name things
- Making the best of the filesystem library
- Managing objects
Skill Level Beginner
1. What Is Modern C++?
2. Tools That Improve Your Code
3. Using the New Features Correctly
4. Don't Reinvent the Wheel
5. Managing Objects
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.