C++ 未找到成员声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9323329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Member declaration not found
提问by codereviewanskquestions
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.
我曾使用常规文本编辑器处理过 C++ 项目。后来,我将所有文件导入到 Eclipse 中,使其调试更容易。
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.
在 Eclipse 中,发生了一件奇怪的事情。即使我已经包含了头文件,它也会抱怨“找不到成员声明”。头文件有函数定义。
How do I fix this problem?
我该如何解决这个问题?
回答by vitaut
"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.
“未找到成员声明”是 Eclipse 静态分析工具 ( codan)产生的错误。如果您收到此错误,但编译成功,则这是误报。已知此工具的旧版本会产生一些误报,例如参见此错误报告。所以我建议将 Eclipse CDT 更新到最新版本。
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 answerfor the details of how to fix it.
可能导致此错误的另一件事是未解决的包含阻止 Eclipse 正确解析您的代码的一部分。Index -> Search For Unresolved Includes
在项目的上下文菜单中进行选择将为您提供未解决的包含列表。有关如何修复它的详细信息,请参阅此答案。
Here's an example:
下面是一个例子:
class C {
void f(std::vector<int>&);
};
void C::f(std::vector<int>&) {} // Member declaration not found
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).
即使您已<vector>
包含但未解析(由于错误配置的包含路径),上述示例也会导致 Eclipse CDT 中出现“未找到成员声明”错误。
回答by Srijeyanthan
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 中也多次遇到此问题。我们可以通过在项目菜单中重建 C/C++ 索引来简单地解决这个问题。:)
回答by Srijeyanthan
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.
我在 Eclipse 中遇到了这个问题,但在终端中构建成功。所以我只是在 Eclipse 中重建 C/C++ 索引: 右键单击项目 -> 索引 -> 重建。
回答by Luca Davanzo
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.
我注意到“未找到成员声明”也会在您创建一个名称已被使用或为 aa 关键字的类时报告。
回答by Kurt Sanger
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 }
for namespace
. Moving the closing }
to the end of the file so that the defined files were now in the namespace
fixed the error message.
我在我的 .cpp 文件中发现了创建此消息的错误。我曾namespace std {
在该文件的前面,我把新的功能,我是闭幕后创造}
的namespace
。将结束移动}
到文件的末尾,以便定义的文件现在在namespace
修复错误消息中。
Example that creates the error.
创建错误的示例。
#include "MyStrFuncs.h"
**namespace** std {
MyStrFuncs::MyStrFuncs() {
// TODO Auto-generated constructor stub
}
MyStrFuncs::~MyStrFuncs() {
// TODO Auto-generated destructor stub
}
} // This ends the **namespace**
//Additional functions will now generate the member declaration not found error...
int MyStrFuncs::str2i(string strIn) {
int results;
istringstream convert(strIn);
if( !(convert)>>results) results = 0;
return results;
}
// Fix by moving closing } for namespace to here. Good luck.
回答by natmat
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.
即使使用 CDT 9.2.1 和 Eclipse Neon 4.6.3,也会报告“未找到成员声明”的问题。正如 Srijeyanthan 所回答的,以下应该解决它:项目 > C/C++ 索引 > 重建。
回答by natmat
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.
我在 eclipse 中拆分源文件和头文件时也遇到了这个问题。我通过“实现方法”eclipse 解决了这个问题,而不是手动键入和构建项目。通过实现方法,“内联函数”将被添加到源文件中。