情況如下:我在頭文件中聲明瞭一個結構體,並在隨附的源文件中將此結構體的實例放入了一個std::map<int, myStruct>
。Eclipse CDT在從std :: map訪問時無法解析結構函數
代碼編譯並運行良好,但Eclipse不會識別函數調用並將其加下劃線爲紅色(無法打開聲明)。
示例代碼:
//myClass.h
struct myStruct{
int returnValue(){
return 4;
}
};
// other class parameters here
,並在源
//myClass.cpp
#include "myClass.h"
#include <iostream>
#include <map>
using std::map;
int main(){
//create map with struct and assign
map<int, myStruct> myMap;
myStruct exampleStruct;
myMap[3]=exampleStruct;
//access struct via [] map operator
std::cout << myMap[3].returnValue() << "\n"; //this line flagged by Eclipse, but works
return 0;
}
就是Eclipse的這種行爲已知的,或者是我的配置錯了嗎?
此外,在一個側面說明,我不是一個專業的progammer,所以風格建議等是非常歡迎的。
編輯:在myClass.h和myClass.cpp
我從來沒有使用eclipse,但是它改變了什麼,如果你讓它成爲'class'而不是'struct'(並且將方法聲明爲'public')?另外,我可以想象,ecplise希望文件名與類名相同,但它又是一個盲目的猜測。 – user463035818
@ tobi303從來沒有嘗試過一個類,但由於其他類功能沒有被標記,我假定Eclipse不介意。另外,Eclipse不關心文件名。 – RemusKaos