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

Unlock this course with a free trial

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

Constructor enhancements

Constructor enhancements

- In this section, we're going to look at various different ways in which constructor syntax has improved in recent years to make it reduced duplication. So we'll have a look at three things in particular: the ability to initialize your data members inline at the point where you declare them in the class. The idea of a delegating constructor where one constructor calls another. And then the third simplification is when you've got inheritance, there's a simpler syntax for calling your superclass constructor. So you have get all of those three techniques in this section. So first of all, when you declare a class, you can initialize your members in line at the point where they've been declared, as I've shown you. The accountHolder data member is initialized in the constructor because you have to pass the value in for the name of the bank accountHolder, but the balance is just zero. And the the bank ID, maybe there's some kind of generator function, which generates like a random ID number…

Contents