Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!agate!ucbvax!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: const member functions ? Message-ID: <6590207@hplsla.HP.COM> Date: 19 Jul 89 17:39:46 GMT References: <6590205@hplsla.HP.COM> Organization: HP Lake Stevens, WA Lines: 17 >Why is this feature useful? Is it to improve code >readability by making it clear when a member function does not alter any >member data? yes. >Is there also a reliability motivation? yes. A compiler can check that the const is not violated. Also, if one tried to pass by reference a const object to a non-const function, a compiler may generate a copy of that const object so that the non-const function can't molest it. This keeps FORTRAN-like problems from happening where that constant 2 you passed by reference gets changed by the routine to actually be 5. More importantly, using const in all the right places now lets me get rid of most of those annoying warning messages when I run +w :-)