Troy demonstrates his solution to creating an integer summation function which can take a variable number parameters.
(upbeat electronic music)…- [Instructor] How'd it go, did you figure out a solution?…Hopefully, yes, it is somewhat similar…to reverse concatenating the strings.…Simply add the first to the remainders,…and don't forget the base case.…Let me show you how I did it.…We begin with the base case, this is…when we only have one argument,…and all it does is return that argument,…so it gets a V, sends a V back out.…Next, we handle the recursiveness.…
Note how the parameters are split up…between the first and the rest,…so we get the first here, we get the rest of them,…and we just say first, and then was say plus,…and we give it back the argument pack.…So it's going to go args star dot dot,…and send it back, and it's going to keep splitting…these up until there's only one,…and then that's going to end at the recursid,…and it's always adding itself together.…And finally, call the function with…a variable number of arguments,…and so that's right here, we're calling it,…and let's go ahead and run this, and see how it looks.…
- 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.