This post introduces usage of “const”, especially terms of “top-level const” and “low-level const”.
Const Associated
Associating pointers, const
is used to declare that pointer is a const, or the object pointed by it is a const. This difference leads to “top-level const” and “low-level const”.
1 | // top-level const and low-level const |
The pointer that points to a const object must be a low-level const
1 | const int x = 99; |
Const in Formal Parameter
In functions, declaring a formal parameter as const follows the principle of using const for variables. The top-level const is ignored whether it is in formal or actual parameters.
1 | // top-level const in actual parameter |
1 | //top-level const in formal parameter |
In Template
Principles described above apply to template as well.
1 | // template |