| |
| | C++ FAQ (part 6 of 8) (Site not responding. Last check: 2007-10-20) |
 | | For example, if class Fred has a const member function[18.9] called inspect(), saying p-> inspect() is OK. But if class Fred has a non-const member function[18.9] called mutate(), saying p-> mutate() is an error (the error is caught by the compiler; no run-time tests are done, which means const doesn't slow your program down). |
 | | The problem with using "Fred const& x" (with the const before the &) is that it could easily be mis-typed as the nonsensical "Fred & const x"[18.7] (with the const after the &). |
 | | E.g., in Set::lookup() const, you might say, Set* self = const_cast< Set*> (this); After this line, self will have the same bits as this (e.g., self == this), but self is a Set* rather than a const Set*. |
| omicron.felk.cvut.cz /FAQ/articles/a2742.html (6054 words) |
|