EC Lecture Notes - Lecture 11: Semicolon
Document Summary
Recall that constants are variables that cannot be changed, and that all const variables must be initialized at time of creation. C++ provides a handy syntax for initializing members of the class called the member initializer list (also called a constructor initializer). This class has two member variables, regvar and constvar. It also has a constructor that takes two parameters, which are used to initialize the member variables. Running this code returns an error, because one of its member variables is a constant, which cannot be assigned a value after declaration. In cases like this one, a member initialization list can be used to assign values to the member variables. The initialization list eliminates the need to place explicit assignments in the constructor body. Also, the initialization list does not end with a semicolon. The member initialization list may be used for regular variables, and must be used for constant variables.