Eclipse method cannot be resolved in a simple C ++ program

I have a problem with Eclipse Indigo complaining that class methods cannot be resolved, but compile in any case and work correctly (AFAIK). This is a very simple program. Here is Population.cpp:

#include <stdlib.h> #include <iostream> #include <time.h> #include "Population.h" Population::Population() { // TODO Auto-generated constructor stub } Population::~Population() { // TODO Auto-generated destructor stub } void Population::initializePop(int numBits, int N) { srand((unsigned)time(0)); for(int i=0; i<N; i++) { x[i] = (char*) calloc(numBits, sizeof(char)); for(int j=0; j<numBits; j++) { if( rand() < 0.5 ) x[i][j] = 0; else x[i][j] = 1; } } } char** Population::getX() { return x; } void Population::printStuff() { std::cout << "Whatever"; } 

Now I am creating this code and everything is fine. In another project in Eclipse, I call this code as follows:

 #include <typeinfo> #include <string.h> #include <iostream> #include "cute.h" #include "ide_listener.h" #include "cute_runner.h" #include "Population.cpp" void testPopulationGeneration() { Population* p = new Population; int N = 10; int bits = 4; char** pop; ASSERTM("Population variable improperly initialized", dynamic_cast<Population*>(p)); std::cout << p->printStuff(); std::cout << "Ok..."; p->initializePop(bits, N); pop = p->getX(); ASSERTM("Pop not correct size.", sizeof(pop) == 10); } 

As you can see, I am also launching the CUTE plugin for TDD in C ++. He does not complain when I declare p as a type of Population, and the first statement passes. I'm a little new to C ++, but I definitely added a project from which Population.cpp was sent to the include path for the test project.

This is not a huge deal, as it does not affect anything obvious to me, but it is still very annoying. I do not see a situation where he should do it.

Thanks for any help!

+7
source share
3 answers

Try the following:

In the project explorer window, right click on your project -> Index -> Rebuild

+19
source

This could be an indexing issue related to #include external headers that were not found. Follow these steps and see if this helps:

  • Go to each of your custom #include (for example, "cute.h" ) and press F3 (ie, "Show Ad"); see if he can access this file or not; if you don’t copy these files to some notepad
  • If the file is not available, find its path in your directory structure; for example, cute.h and ah are located on, C://Eclipse/MyWork/Workspace/Project/include_1 and ide_listener.h are at, C://Eclipse/MyWork/Workspace/Project/include_2 ", then copy both paths to the folder on some notepad
  • Inside Eclipse, go to Project -> Properties -> C/C++ General -> Paths and Sybmols ; You will see several tabs like Includes , Sybmols , Library Paths ...
  • Click Library Paths -> Add -> Workspace... -> <locate the above folder paths> and click OK
  • Allows rebuilding the indexer; now follow step (1) again; hopefully files should be available
  • For security in larger files go to Window -> Preferences -> C/C++ -> Editor -> Scalability -> "Enable scalability mode when ..." and set the number of lines to some large number, for example 500000 and click "OK";

The last step is necessary because when your file grows in the line number, and if it exceeds the number indicated above, then the eclipse will stop showing definitions for some reasons of "scalability", although it will be indexed.

+10
source

sizeof(pointer) returns the size of the pointer (4 on 32-bit systems and 8 on 64-bit), not the size of what it points to! Save the dimensions in the class and add a function to return them.

Also, in initializePop you should not allocate the actual X array?

 X = calloc(N, sizeof(char *)); 

Or rather, you should use new to highlight, since you are using C ++:

 X = new char* [N]; 

and later:

 X[i] = new char [numbits]; 
+3
source

All Articles