【发布时间】:2017-02-04 04:02:25
【问题描述】:
我收到一个奇怪的错误,说我的变量没有声明,即使我已经在 main.xml 中声明了它们。我错过了什么吗?
错误 4 错误 C2065:'destination':未声明的标识符 c:\users\owner\documents\visual studio 2012\projects\project36\project36\source.c 26 1 Project36
我正在用 C 编程。
变量声明:
char sourcePiece;
char destination;
函数调用:
askForMove(sourcePiece, destination);
函数定义:
void askForMove(char sourcePiece, char destination) {
char sourcePiece;
char destination;
printf("\nEnter your desired move. First enter the starting position, followed by the ending position in letters: ");
scanf(" %c %c", &sourcePiece, &destination);
}
原型:
void askForMove(char, char );
【问题讨论】:
-
你能显示整个代码吗?
-
你不是在函数中复制char源和目标吗?
-
我认为参数名称并不重要。他们是不同的,不是吗?是的,我可以发布整个代码。
-
你在读你写的代码吗?您同时在范围内有两个
char SourcePiece变量(您作为参数接收到askForMove的一个变量和一个您在askForMove内声明的新变量)。 -
问题描述不准确。
askForMove的代码无效(正如上面的 cmets 中已经解释的那样),但引用的错误消息甚至与askForMove中的错误不匹配。触发引用错误消息的第 26 行代码在哪里?