6.2.3. const Parameters and Arguments

Image

When we use parameters that are const, it is important to remember the discussion of top-level const from § 2.4.3 (p. 63). As we saw in that section, a top-level const is one that applies to the object itself:

const int ci = 42;     // we cannot change ci; const is top-levelint i = ci;            // ok: when we copy ci, its top-level const is ignoredint * const p = &i;    // const is top-level; we can't assign to p*p = 0;                // ok: changes through p are allowed; i is now 0

Just as in any other initialization, when we copy an argument to initialize a parameter, top-level consts are ignored. As ...

Get C++ Primer, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.