Key Takeaways
Get a recap of all the concepts learned in this chapter.
In this chapter, we learned that const
for class type parameters should be used with references or pointers to avoid copying and accidentally modifying the original object. We also learned odd behaviors of C++ regarding function overloads or their lack when const
is used for the parameters.
-
Use
const
for primitive data-type parameters when we want to show they won’t get modified. -
Use
const&
for object-type parameters when we have to avoid copying and modifying them. -
Be aware that
const
qualification might be ignored, and when we create two overloads, the compiler will not differentiate them, and the compilation will fail. -
Declarations with non-
const
parameters might match definitions withconst
parameters. However, don’t rely on this feature because it degrades readability
Get hands-on with 1400+ tech skills courses.