From the course: Modern C++: Advanced Techniques and Features

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Miscellaneous language enhancements

Miscellaneous language enhancements - C++ Tutorial

From the course: Modern C++: Advanced Techniques and Features

Miscellaneous language enhancements

- In this section, we're going to look at miscellaneous language enhancements in C++ over the last many years. We'll also have a look at some additional language enhancements in the next section. So first of all, we're going to see, you can declare variables in the first part of an if statement and a switch statement. Have a look at this. I've got an if statement. Before the actual test, you can have a variable declaration section. As you can see here, I've declared a variable that will only be in scope for this if construct, okay? It's a bit like, I mean, it's a little bit reminiscent of the way we've written for loops for hundreds of years. When you have a for loop, you can declare variables in the first part of a for loop, and then you can have the test part and the update part. You can declare variables at the beginning of a for loop. You can do the same now in an if statement. So it's quite handy. You can do some work to get a result at m here, my favorite month. And then you can…

Contents