3

I am receiving an error message for not naming a type, as follows:

error: ‘hash_map’ does not name a type typedef hash_map<const char*,LexUnitX*,MLexUnitFunctions> MLexUnit;

The code in question creates a custom hash_map type using a LexUnitX-type struct as shown below:

typedef struct {
    int iLexUnit;                                   // lexical unit unique identifier
    const char *strLexUnit;                     // lexical unit as an array of characters (a word, a syllable, etc.)
    VLexUnit vLexUnitPronunciations;            // alternative pronunciations of the lexical unit
} LexUnitX;

Code for the VLexUnit vector; vector of LexUnit-type pointers

// lexical unit transcription
typedef struct {
   int iLexUnit;                            // lexical unit id (unique correspondence id <> lexical unit in str format)
   int iLexUnitPron;                        // lexical unit id (unique correspondence id <> lexical unit + pronunciation)
   int iIndex;                              // index of the lexical unit within the lexicon file
   vector<int> vPhones;                 // phonetic transciption 
   unsigned char iPronunciation;        // pronunciation number
   unsigned char iType;                 // standard / filler / sentence delimiter
   float fProbability;                  // pronunciation probability (respect to alternative ones of the same lex unit)
   float fInsertionPenalty;         // penalty for inserting this lexical unit during decoding
} LexUnit;  

class LexiconManager;

typedef vector<LexUnit*> VLexUnit;

and finally the hash_map type to map characters to their corresponding data structure:

// maps lexical units as strings of characters to their corresponding data structure
#if defined __linux__ || defined __APPLE__ || __MINGW32__
typedef std::tr1::unordered_map<const char*,LexUnitX*,MLexUnitFunctions,MLexUnitFunctions> MLexUnit;
#elif _MSC_VER < 1700
typedef hash_map<const char*,LexUnitX*,MLexUnitFunctions> MLexUnit;
#else
    #error "unsupported platform"
#endif

I am not sure what exactly I am doing wrong syntatically here to cause the error.

user02103012
  • 61
  • 1
  • 7

2 Answers2

1

Well, if you are using a standard library implementation which provides hash_map (which is not part of the standard), you need to #include <hash_map> and call it std::hash_map (it was placed in the std namespace by both MSVC and GNU, according to this answer.)

Community
  • 1
  • 1
Nick Matteo
  • 4,453
  • 1
  • 24
  • 35
  • stl is _not_ the standard library. Read the link you referred to more carefully. – Otheus Jul 28 '23 at 15:32
  • I did not say anything about the STL and I don't know why you brought it up. I said that hash_map is not part of the standard but is included in some standard library implementations such as those shipped with MSVC and GCC. – Nick Matteo Jul 28 '23 at 19:27
1

If you are using Visual Studio 2003 (or more recent), you should use stdext namespace. See https://msdn.microsoft.com/en-us/library/0d462wfh(v=vs.80).aspx :

In Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. See The stdext Namespace for more information.

_MSC_VER table (How to Detect if I'm Compiling Code With Visual Studio 2008?):

MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
MSVC++ 9.0  _MSC_VER == 1500 (Visual Studio 2008)
MSVC++ 8.0  _MSC_VER == 1400 (Visual Studio 2005)
MSVC++ 7.1  _MSC_VER == 1310 (Visual Studio 2003)

So looks like your code is incorrectly check _MSC_VER

Community
  • 1
  • 1
Vadim Key
  • 1,242
  • 6
  • 15