Eclipse CDT 在从 std::map 访问时无法解析结构函数



情况如下:我在头文件中声明了一个结构体,在附带的源文件中,我将该结构体的实例放在std::map<int, myStruct> .

代码编译并运行良好,但是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的这种行为是已知的,还是我的配置错误?

另外,顺便说一句,我不是一个专业的程序员,所以风格建议等是非常受欢迎的:)

修改myClass.h和myClass.cpp的错别字

修复错字后,代码很好,甚至没有警告就被接受了。所以我只能想象这可能是Eclipse配置中的一个问题。

好吧,这太尴尬了。我在eclipse中运行示例代码(实际示例非常长,并且依赖于一些自定义库),eclipse对map中结构的函数没有任何问题。

所以我重建了真实项目的索引,现在一切都很好。这很奇怪,因为当我创建一个新类时,Eclipse似乎总是更新索引,但这次没有……所以感谢所有阅读和回答的人,但问题已经解决了。