Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse method could not be resolved for vector of vectors

Tags:

c++

eclipse

Whenever I try to access a method or field of a vector element via a index operator, e.g. bar[0].push_back(0) on vector< vector< int > > i get a "Method could not be resolved" Semantic Error from eclipse.

The code compiles just fine with g++ -Wall or clang++ - here is a short example.

#include <set>
#include <vector>
#include <iostream>

int main()
{
    std::vector< std::vector < int > > bar(10);
    bar[0].push_back(0);    // eclipse "method 'push_back' could not be resolved
    (bar[0]).push_back(1);  // eclipse "method 'push_back' could not be resolved
    bar[0][0] = 0;      // This and all else is just fine for eclipse
    std::vector<int> &bar0 = bar[0];
    bar0.push_back(2);
    std::vector<int> *pbar0 = &bar[0];
    pbar0->push_back(3);
    return 0;
}

I have a simmilar issue with std::vector<std::pair<int, int> >::iterator trying to access iter->first. (Field 'first could not be resolved).

It is a C/C++ project, .cpp file, in Eclipse 4.2.1, there are no unresolved inclusions.

I am completely lost here - how can I get rid of this eclipse error?

Update: I have also tried this with the latest available Version: Juno Service Release 1. Same result.

Update2: I actually noticed that with a brand new project, the error does not occur, so I should be able to eventually determine what setting is responsible for this error. So far I could not identify anything, no (non inbuilt) symbols are defined and the paths look good as well.

like image 894
Zulan Avatar asked Nov 04 '22 09:11

Zulan


1 Answers

Recreating the Project from scratch fixed the issue. It appears that the project was created by a previous Version of eclipse, possibly causing the problem. Due to the large number of changes in .project and .cproject it was not possible to determine the specific cause.

like image 119
Zulan Avatar answered Nov 08 '22 03:11

Zulan