mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
parent
a96fed9c99
commit
32d6313607
|
@ -11076,9 +11076,11 @@ Unnamed constants embedded in expressions are easily overlooked and often hard t
|
||||||
|
|
||||||
No, we don't all know that there are 12 months, numbered 1..12, in a year. Better:
|
No, we don't all know that there are 12 months, numbered 1..12, in a year. Better:
|
||||||
|
|
||||||
constexpr int month_count = 12; // months are numbered 1..12
|
// months are indexed 1..12
|
||||||
|
constexpr int first_month = 1;
|
||||||
|
constexpr int last_month = 12;
|
||||||
|
|
||||||
for (int m = first_month; m <= month_count; ++m) // better
|
for (int m = first_month; m <= last_month; ++m) // better
|
||||||
cout << month[m] << '\n';
|
cout << month[m] << '\n';
|
||||||
|
|
||||||
Better still, don't expose constants:
|
Better still, don't expose constants:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user