Overloading and const
Parameters
As we saw in § 6.2.3 (p. 212), top-level const
(§ 2.4.3, p. 63) has no effect on the objects that can be passed to the function. A parameter that has a top-level const
is indistinguishable from one without a top-level const
:
Record lookup(Phone);Record lookup(const Phone); // redeclares Record lookup(Phone)Record lookup(Phone*);Record lookup(Phone* const); // redeclares Record lookup(Phone*)
In these declarations, the second declaration declares the same function as the first.
On the other hand, we can overload based on whether the parameter is a reference (or pointer) to the const
or nonconst
version of a ...
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.