vendredi 14 août 2020

(C++) Is it possible to make the counter variable of a for-loop immutable/const-safe/read-only inside the loop? [duplicate]

I've been in a couple of situations where I want the counter i to be const-safe. Below is a banal example of what I mean. Is there a way to achieve this?

for (int i = 0; i < 10; ++i)
{
    ++i;   // I don't want this to be allowed
    cout << i << endl;
}

Aucun commentaire:

Enregistrer un commentaire