错误C3861:'elbow':找不到标识符

编程入门 行业动态 更新时间:2024-10-22 10:51:44
本文介绍了错误C3861:'elbow':找不到标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我有一个问题,即我使用C ++创建了一个Windows窗体应用程序,并且有一个通过串口发送命令的程序。 Communicate.cpp是我的主要形式。我有Commands.cpp,它保存命令以发送串行端口。在Communicate.h中,我有一个调用函数的点击事件 elbow()但是每当我尝试构建它时,我都会收到错误:错误C3861:'elbow':标识符未找到I在Communicate.cpp中包含Commands.h,Commands.cpp中包含Commands.h。 Communicate.h函数调用:

Hi there, I have an issue whereby I have created a Windows Forms application using C++ and have a program which sends commands through a serial port. Communicate.cpp is my main form. I have Commands.cpp which holds commands to send down the serial port. In Communicate.h I have a click event which calls function "elbow()" however whenever I try to build it I get the error: "Error C3861: 'elbow': identifier not found" I have included Commands.h in Communicate.cpp and Commands.h is included in Commands.cpp. Communicate.h function call:

private: System::Void testBtn_Click(System::Object^ sender, System::EventArgs^ e) { elbow(2, 1); }

Communicate.cpp包括:

Communicate.cpp includes:

#include "Communicate.h" #include "Commands.h"

Commands.cpp:

Commands.cpp:

#include "Commands.h" #include "Communicate.h" using namespace SerialCommunications; using namespace System; using namespace System::IO::Ports; void elbow(int dir, int amt) { array<Byte>^ cmd = { 0xff, 0xff, 0xff }; //Communicate::serialPort1->Write(cmd, 0, 3); for (int i = 0; i < 255; i++) { Communicate::serialPort1->Write(cmd, 0, 3); //for (int i = 0; i < 1000; i++) cmd[2]--; } return; //Communicate::serialPort1->Write(cmd, 0, 3); }

提前致谢, Max

Thanks in advance, Max

推荐答案

这里有两个问题。 - 一个是由C / C ++语言的语法引起的,它只能理解符号一个给定的位置,如果该符号在之前已经宣布那个位置。正如CPallini在他的解决方案中指出的那样,你必须在编译器可以找到它的地方放置函数 elbow()的声明,之前它遇到它的使用。 - 修复第一个问题后,第二个问题会以链接器错误的形式出现:通过实现函数标题 Communicate.h 中的elbow ,并在至少两个编译单元中包含该标头, Commands.cpp 和 Communcate.cpp ,你生成两个相同功能的组合,链接器将不知道使用哪一个! 第二个问题的解决方案是将函数 testBtn_Click()的实现移动到 Communicate.cpp 。请注意,如果您在 Commands.h <内有 elbow()声明,这也将解决第一个问题br /> 摘要: 1.确保声明 elbow()在 Commands.h 2.将 testBtn_Click()的实现移动到 Communicate.cpp PS:你得到的错误的可能原因是编译器试图编译通信.h,它遇到#include Communicate.h,其中包含导致错误的实现。在那之后#include你也#included Commands.h,它可能有缺少的声明,编译器不能向前看代码,只能向后看。 There are two problems here. - One is caused by the grammar of the C/C++ language, which does only understand symbols at a given position, if that symbol has been declared before that position. As CPallini has pointed out in his solution, you must put a declaration of the function elbow() somewhere where the compiler can find it, before it encounters its use. - The second issue will hit you in the form of a linker error after you fix the first: by implementing the function elbow inside the header Communicate.h, and including that header in at least two compilation units, Commands.cpp and Communcate.cpp, you generate two compilates of the same function, and the linker will not know which one to use! The solution for the second issue is to move the implementation of the function testBtn_Click() into Communicate.cpp. Note that this will also fix the first issue, if you have a declaration of elbow() inside Commands.h Summary: 1. make sure there is a declaration of elbow() in Commands.h 2. Move the implementation of testBtn_Click() into Communicate.cpp P.S.: the probable reason for the error you've got is that the compiler tries to compile Communicate.h, and there it encounters #include Communicate.h, which contains the implementation causing the error. While after that #include you've also #included Commands.h, which presumably has the missing declaration, the compiler can't look forward in code, only backward.

奇怪的是它可能看起来,你需要让 Communicate.h 文件知道 elbow 函数原型,因为函数调用是在这样的头文件中执行。 你应该把 elbow 原型放在 Communicate.h (在 testBtn_Click 方法之上)或 Communicate.h 所包含的文件中(它也可以包括在内) Communicate.cpp ,但高于 Communicate.h 包含)。 As strange as it may look, you need to make the Communicate.h file aware of the elbow function prototype, because the function call is performed in such a header file. You should put elbow prototype either in Communicate.h (above the testBtn_Click method) or in a file included by Communicate.h (it could be included as well by Communicate.cpp, but above Communicate.h inclusion).

更多推荐

错误C3861:'elbow':找不到标识符

本文发布于:2023-10-07 15:22:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469758.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   找不到   错误   elbow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!