Use const to improve the robustness of the function

11.1 Use const to improve the robustness of functions
Seeing the const keyword, C++ programmers may first think of const constants. This is not a good
reflex. If you only know that constants are defined with const, then it is equivalent to using gunpowder only for making firecrackers. The greater
charm of const is that it can modify function parameters, return values, and even function definition bodies.
const is the abbreviation of constant, meaning "constant and unchanging". Const been modified things are subject to mandatory insurance
protection, you can prevent accidental changes, can improve the robustness of the program. So many C++ programming books suggest: "Use
const whenever you need".
11.1.1 modified by const function parameters
if the parameter for output, regardless of what type of data it is, and whether it is a "pointer is passed" or "drawing
by passing" can not add the const modifier, otherwise parameter will lose output .
const can only modify input parameters:

Guess you like

Origin blog.csdn.net/geggegeda/article/details/5306105