[英]Compiler says variable was not declared, but it is declared on the previous line
我使用 MingW 作为我的编译器。 我已经声明了一个变量strl
,但它说它没有在它正下方的行中声明。
struct idstruct {
char * path;
lua_State **state;
};
idstruct ids[] = {};
int nids = 0;
static char* getPath(lua_State **state) {
std::cout << state;
for (int on = 0; on < nids; on++)
idstruct strl = ids[on];
if (strl.state == state) {
return strl.path;
}
}
}
您在 for 循环主体的开头缺少一个花括号。 当您到达以下if
语句时, strl
已超出范围。
你在 for 循环中没有使用大括号,所以它只是一个单行,尽管你有缩进。 因此该变量不在它下面的if
语句的范围内。
尝试这个:
for (int on = 0; on < nids; on++) { // add a brace here
idstruct strl = ids[on];
if (strl.state == state) {
return strl.path;
}
} // and here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.