Eclipse Method could not be resolved in a simple program C++

40,997

Solution 1

Try this:

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

Solution 2

This could be an indexing issue related to external #include headers not found. Follow the steps below and see if it helps:

  1. Go to each of your custom #include (e.g. "cute.h") and press F3 (i.e. "Show declaration"); see if it's able to access that file or not; if not copy those files on some notepad
  2. If the file is not accessible, then locate it paths in your directory structure; e.g. "cute.h" and "a.h" are located at, "C://Eclipse/MyWork/Workspace/Project/include_1" and "ide_listener.h" is located at,"C://Eclipse/MyWork/Workspace/Project/include_2", then copy both the folder paths on some notepad
  3. Inside Eclipse go to Project -> Properties -> C/C++ General -> Paths and Sybmols; you will see several tabs as Includes, Sybmols, Library Paths ...
  4. Click Library Paths -> Add -> Workspace... -> <locate the above folder paths> and press OK
  5. Let the indexer rebuild; now again follow the step (1); hopefully the files should be accessible
  6. For future safety for larger files, go to Window -> Preferences -> C/C++ -> Editor -> Scalability -> "Enable scalability mode when ..." and set the number of lines to some big number such as 500000 and press "OK";

The last step is needed, because when your file grows in line number and if exceeds the above number then eclipse will stop showing definitions for some "scalability" reasons, even though it would have indexed.

Solution 3

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 shouldn't you allocate the actual X array?

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

Or rather, you should use new for allocation since you are using C++:

X = new char* [N];

and later:

X[i] = new char [numbits];

Solution 4

Not that i'm any expert at all but i just had a similar problem using.empty for whatever reason it will work if you change char to string minor change but resolved the issue on my program

Share:
40,997
F_C
Author by

F_C

Updated on December 02, 2020

Comments

  • F_C
    F_C over 3 years

    I have an issue with Eclipse Indigo complaining that methods of a class couldn't be resolved, but compiling anyway and working correctly (AFAIK). It's 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 build that code and everything is fine. In another project within Eclipse, I'm calling this code like this:

    #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'm also running the CUTE plugin for TDD in C++. It doesn't complain when I declare p as type Population and the first assertion passes. I'm somewhat new to C++, but I did make sure to add the project that Population.cpp is from to the include path for the test project.

    It's not a huge deal as it's not affecting anything obvious to me, but it's still very annoying. I don't see a situation where it should do this.

    Thanks for any help!

  • F_C
    F_C over 12 years
    Thanks for the tip! It doesn't answer the question but the sizeof tip helped me out. I guess I've been using higher level languages for too long. Little rusty on the basics like that. It almost seems like a hack to just store the sizes along with the array itself, but I guess if the size of the array is going to be command-line input, there's no better way to do it in C++.
  • F_C
    F_C over 12 years
    I tried going through all my includes and Eclipse can find all of the sources, so that appears not to be my problem.
  • inder
    inder almost 10 years
    I am not seeing the "Library Paths" under Paths and Symbols on my ADT. Anyone knows where this is moved to now? Thanks.
  • iammilind
    iammilind almost 10 years
    @inder, did you mean Windows > Preferences > Debug/Release > Source Lookup Path?
  • ulyssis2
    ulyssis2 about 8 years
    This solution works for me, thanks. I am using Eclipse mars. 2 on mac.