GCC 错误:declaration of … shadows a parameter
问题:
你遇到以下形式的 GCC 错误消息
shadowing_error.txt
error: declaration of ... shadows a parameter在你的代码中某处有一个带参数的函数
shadow_example.cpp
void doSomething(int arg) {/*...*/}然而,在函数中某处你想声明一个与某个函数参数同名的变量。
声明一个名称已引用另一个变量的变量称为遮蔽。在这种情况下,你遮蔽了函数参数。
例如,在
shadow_example.c
void doSomething(int arg) {
char* arg = "";
}char* arg 遮蔽了函数参数 int arg
识别原因:
文件和行号指的是遮蔽参数的变量声明。
解决错误:
重命名遮蔽参数的变量或重命名参数本身
在上面的示例中,你需要重命名 char arg(例如为char arg2)或 int arg。
Check out similar posts by category:
Allgemein
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow