I recently received some (closed source) third-party code to work with. While scrolling through all the classes (c++) I found some interesting snippet that I've never seen anyone doing before.
void ns::somefunc() {
enum { MAX_ATTEMPS = 5 }; // why not 'const int max_attemps = 5;'?
for (int i = 0; i < MAX_ATTEMPS; ++i) {
/* some code without reference to MAX_ATTEMPS or i */
}
}
I've never seen this, why would one create an unnamed enum - within a function - with a single enumerator set to a specific value instead just using const int max_attemps = 5;
? Especially since neither i
nor MAX_ATTEMPS
are used inside the loop or anywhere else in the functions scope.