6.2.3. const
Parameters and Arguments
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 const
s are ignored. As ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.