16

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
  • Does eclipse know where to look for the header file? If it does, then we'll probably need some more info – Neowizard Feb 17 '12 at 08:15

7 Answers7

24

"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:

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).

Community
  • 1
  • 1
vitaut
  • 49,672
  • 25
  • 199
  • 336
9

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. :)

Srijeyanthan
  • 126
  • 1
  • 2
3

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.

1

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.

Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
0

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.

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.
ByteHamster
  • 4,884
  • 9
  • 38
  • 53
0

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.

natmat
  • 21
  • 3
0

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.