EC Lecture Notes - Lecture 11: Semicolon

7 views2 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents