Constants

 < Day Day Up > 



A constant is an object in your program that you intend to remain unchanged during its lifetime. The use of constants can vastly improve the readability and maintainability of your code.

You can declare constants in C++ using the keyword const. Constants have to be defined at the point of declaration. The following statement gives an example of a constant declaration and definition:

const int MAX_COUNT = 25;

There is an exception to the define-at-the-point-of-declaration rule, and that is when you are declaring constants for use in classes or structures. In chapter 11 I will show you how to use constructors to define class constant members.

Once you have defined the constant, any attempt to change its value will be met with disapproval from the compiler.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net