C++ Lookup of i changed for ISO

前端 未结 3 1331
我寻月下人不归
我寻月下人不归 2021-01-25 00:42

I have the following code for a dictionary.

void Dictionary::translate(char out_s[], const char s[])
{

for (int i=0;i

        
3条回答
  •  孤城傲影
    2021-01-25 01:07

    Not "for iso" (perhaps read the entire error message...), but for ISO C++. The problem is that the scope of the i variable is only the for loop (since its definition is inside the initialization of the loop). Since it seems you want to use it outside the loop, declare it like so:

    int i;
    for (i = 0; i < foo; i++) {
        // ...
    }
    
    do_safe_stuff_with(i); // valid
    

提交回复
热议问题