0

my project was working fine and then when i change something in another header file i suddenly got this error:

Error C2065 'map': undeclared identifier

although i did #include <map>

part of Game.h:

#include <map>

class Game{

    Game();

}

the line which gives me the error in Game.cpp:

_results.insert(map<std::string, int>::value_type(_players[i]->getUsername(), 0));

this code line worked fine ! until some point

Tomer
  • 163
  • 1
  • 1
  • 8

1 Answers1

0

My guess is that at one point, you either had a class named map in the global namespace, which provided an interface similar to std::map, or more likely, you were relying on a using namespace std; directive that has since been removed (whether unintentionally or not; perhaps someone else had one in a header you were using, but removed it when they realised that was a bad idea). Either put a using-directive for std or a using-declaration for std::map in the code block containing that line, or explicitly use std::map whenever you want to use the C++ standard library map class; the latter is recommended, because it makes code clearer and cleaner.

If you were using a custom map class before, check that its header is still #included, and that it doesn't run into the same namespace issue.

  • #include using namespace std; all tstrings are undeclared under visual stupidity 2003, HALLLLLP. – Owl Jun 28 '17 at 14:48