未找到会员声明
我曾使用常规文本编辑器开发过一个 C++ 项目。后来我将所有文件导入到Eclipse中,以便于调试。
在 Eclipse 中发生了一件奇怪的事情。即使我已经包含了头文件,它也会抱怨“未找到成员声明”。头文件有函数定义。
我该如何解决这个问题?
I have worked on a C++ project using a regular text editor. Later, I imported all the files to Eclipse to make it debugging easier.
In Eclipse a weird thing happens. It complains "Member declaration not found" even if I have included the header file. The header file has the function definition.
How do I fix this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
“未找到成员声明”是 Eclipse 静态分析工具 (codan) 产生的错误。如果出现此错误,但编译成功,则这是误报。众所周知,该工具的旧版本会产生一些误报,例如,请参阅 此错误报告。因此我建议将 Eclipse CDT 更新到最新版本。
可能导致此错误的另一件事是未解析的包含,它阻止 Eclipse 正确解析部分代码。选择
索引 ->在项目的上下文菜单中搜索未解决的包含
将为您提供未解析的包含列表。有关如何修复此问题的详细信息,请参阅此答案。下面是一个示例:
即使您包含了
但未解析(由于包含路径配置错误),上面的示例也会在 Eclipse CDT 中导致“未找到成员声明”错误。"Member declaration not found" is an error produced by the Eclipse static analysis tool (codan). If you get this error, but the compilation succeeds this is a false positive. Older versions of this tool are known to give some false positives, see for example this bug report. So I recommend updating Eclipse CDT to the most recent version.
Another thing that may cause this error is an unresolved include that prevents Eclipse from parsing a portion of your code correctly. Selecting
Index -> Search For Unresolved Includes
in the context menu of the project will give you the list of unresolved includes. See this answer for the details of how to fix it.Here's an example:
The above example causes "Member declaration not found" error in Eclipse CDT even if you have
<vector>
included but unresolved (due to misconfigured include paths).虽然构建成功,但我在 Eclipse 中也多次遇到此问题。我们可以通过在项目菜单中重建C/C++索引来简单地解决这个问题。 :)
I also experienced this problem several times in Eclipse though building is successful. We can simply solve this problem by rebuild the C/C++ index in project menu. :)
我在 Eclipse 中遇到这个问题,但在终端中构建成功。所以我只是在 Eclipse 中重建 C/C++ 索引:
右键单击项目 ->索引->重建。
I got this problem in Eclipse, but building in terminal was successful. So I just rebuild the C/C++ index in Eclipse:
Right click on the project -> index -> rebuild.
我注意到,当您创建一个名称已被使用或为关键字的类时,也会报告“未找到成员声明”。
I noticed that "Member declaration not found" will report also when you create a class with a name that is already used or is a a keyword.
我在创建此消息的 .cpp 文件中发现了一个错误。我在文件的前面放置了
namespace std {
,并且在namespace
的关闭}
之后放置了我正在创建的新函数。将结束的}
移动到文件末尾,以便定义的文件现在位于命名空间
中,从而修复了错误消息。创建错误的示例。
I found an error in my .cpp file that creates this message. I had
namespace std {
in the front of the file, and I placed new functions that I was creating after the closing}
fornamespace
. Moving the closing}
to the end of the file so that the defined files were now in thenamespace
fixed the error message.Example that creates the error.
即使使用 CDT 9.2.1 和 Eclipse Neon 4.6.3 也会报告“未找到成员声明”问题。
正如 Srijeyanthan 所回答的,以下问题应该可以解决:
项目>> C/C++索引>重建。
Even with the CDT 9.2.1 and Eclipse Neon 4.6.3 "Member declaration not found" problems are reported.
As answered by Srijeyanthan, the following should resolve it:
Project > C/C++ Index > Rebuild.
我在 eclipse 中拆分源文件和头文件时也遇到了这个问题。我通过“实现方法”eclipse 解决了这个问题,而不是手动键入和构建项目。通过实现方法,“内联函数”将被添加到源文件中。
I also experienced this problem while splitting source and header files in eclipse.I resolved this by "implementing methods" eclipse instead of manual typing and building the project.By implementing methods "inline functions" will be added to source file.