...
Noncompliant Code Example
| Code Block | ||
|---|---|---|
| ||
char c = 'c'; char &const p = c; p = 'p'; cout << c << endl; |
...
If constant access is required, instead of using a const reference, one can use a const pointer:
| Code Block | ||
|---|---|---|
| ||
char c = 'c'; char *const p = c; *p = 'p'; // causes compiler error cout << c << endl; |
...