Discussion: The constings discussed here are constings used to modify the function, rather than the const used to modify the variable. Although it is the same keyword, but Yayv still feels better to understand them as 2 keywords.
The CONST key in C is used to represent a constant, and the const is also used to modify the function. Yayv's clear concept is: Constly modified function can only be a member function of the class, because in the modified function modified, the compiler is responsible for the user variable of the protection class is not modified. Relative, Mutable is a member variable used to modify the class, so that the variable can be modified in the member function modified by Const. And the const modified function can only be a member function of the class, and the Mutable modified variable can only be a member variable of the class. It's just a pair of family directions ~
There have been three problems here:
First: Why is the member variable of the protection class is not modified
Second: Why protect the member variable with const, but also define a mutable keyword to break through the CONST blockade line?
Third: Is there any two keywords that do not use const and mutable?
Yayv's views on these three issues are:
The user variables of the protection class are not modified in the member function. To ensure the logic of the model correctly, by avoiding the state of modifying the class object in the function with the const keyword. And in all places where the member function can be used more accurately, the impact of the blending of the member function can be predicted.
Mutable is to break through the CONST blockade line, allowing some of the secondary or adjuvant member variables that can be changed at any time.
No use and mutable keywords are of course not fault, the const and mutable keywords are only given more design constraints and design flexibility to modeling tools, and programmers can handle more logical inspection issues to compilers and build. The mold tool is done, thereby alleviating the burden of programmers (Yayv think this is just the handload to the designer ~, :(, does not reduce any workload).
If the development process has a stricter iterative process, using these two keywords should be more effectively reflecting their role.