每當我嘗試通過索引運算符訪問矢量元素的方法或字段時,例如, bar[0].push_back(0)
on vector< vector<int> >
我得到一個「方法無法解決」來自eclipse的語義錯誤。Eclipse方法無法解析矢量矢量
該代碼與g++ -Wall
或clang++
編譯得很好 - 這裏是一個簡短的例子。
#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;
}
我有一個std::vector<std::pair<int, int> >::iterator
問題simmilar試圖訪問iter->first
。 (領域'第一無法解決)。
它是一個C/C++項目,.cpp文件,在Eclipse 4.2.1中,沒有未解決的包含。
我完全失去了這裏 - 我該如何擺脫這個月食錯誤?
更新:我也嘗試過使用最新的可用版本:Juno Service Release 1.同樣的結果。
Update2:我實際上注意到,對於一個全新的項目,錯誤不會發生,所以我應該能夠最終確定導致此錯誤的設置。到目前爲止,我無法識別任何東西,也沒有定義(非內置)符號,路徑也很好看。
簡單的回答:擺脫Eclipse! :-) –
Eclipse 4.2.1爲我處理好代碼示例。你的「路徑和符號」配置是否正確?儘管編譯器可能正在尋找正確的位置,但Eclipse本身可能會指向任何地方。另外:不要聽傑裏!堅強! ;) – user1201210