我使用 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
语句的范围内。
试试这个:
for (int on = 0; on < nids; on++) { // add a brace here
idstruct strl = ids[on];
if (strl.state == state) {
return strl.path;
}
} // and here
关于c++ - 编译器说变量没有声明,但它在前一行声明了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096826/