May 2012
Intermediate to advanced
679 pages
16h 56m
English
In previous example, we saw the use of “const” with pointers. It is also possible to use it with class objects and class members.
It is possible to declare an object as constant. Assume we have class Point suitably defined. Now we are allowed to declare
const Point pt1;
It declares a constant object named pt1 of type Point. You will ask me what the use of this declaration is. Well, now compiler will not allow us to modify this object. It means you cannot modify even its public data members! Well we may say that we have achieved “read only” objects.
C++ allows us to make a data member constant. The constants are normally initialized at the declaration. ...
Read now
Unlock full access