mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
Updated example for Con.1
The original example was good, but it used a reference where the point of Con.1 is about declaring objects themselves const
This commit is contained in:
@@ -13975,11 +13975,9 @@ Prevents accidental or hard-to-notice change of value.
|
|||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
for (const string& s : c) cout << s << '\n'; // just reading: const
|
for (const int i : c) cout << i << '\n'; // just reading: const
|
||||||
|
|
||||||
for (string& s : c) cout << s << '\n'; // BAD: just reading
|
for (int i : c) cout << i << '\n'; // BAD: just reading
|
||||||
|
|
||||||
for (string& s : c) cin >> s; // needs to write: non-const
|
|
||||||
|
|
||||||
##### Exception
|
##### Exception
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user