2010-01-18 17 views
5

के साथ घोषित नहीं किया गया था, मैं sgi हैश_मैप का उपयोग करने की कोशिश कर रहा हूं।'हैश_मैप' को इस दायरे में जी ++ 4.2.1

#include <list> 
#include <iostream> 
#include <string> 
#include <map> 
#include <cstring> 
#include <tr1/unordered_map> 
#include <ext/hash_map> 


using namespace std; 
struct eqstr 
{ 
    bool operator()(const char* s1, const char* s2) const 
    { 
    return strcmp(s1, s2) == 0; 
    } 
}; 


int main() 
{ 
    hash_map<const char*, int, hash<const char*>, eqstr> months; 

    months["january"] = 31; 
    months["february"] = 28; 
    months["march"] = 31; 
    months["april"] = 30; 
    months["may"] = 31; 
    months["june"] = 30; 
    months["july"] = 31; 
    months["august"] = 31; 
    months["september"] = 30; 
    months["october"] = 31; 
    months["november"] = 30; 
    months["december"] = 31; 

    cout << "september -> " << months["september"] << endl; 
    cout << "april  -> " << months["april"] << endl; 
    cout << "june  -> " << months["june"] << endl; 
    cout << "november -> " << months["november"] << endl; 
} 

gcc4.2 पर मैं, जबकि एक ही कोड 3.4 के साथ संकलन त्रुटि

listcheck.cc: In function 'int main()': 
listcheck.cc:22: error: 'hash_map' was not declared in this scope 
listcheck.cc:22: error: expected primary-expression before 'const' 
listcheck.cc:22: error: expected `;' before 'const' 
listcheck.cc:24: error: 'months' was not declared in this scope 

हो रही है।

उत्तर

5

फ़ाइल शामिल करें <ext/hash_map>GNU extension हैश मैप क्लास को संदर्भित करता है और इसे नामस्थान __gnu_cxx में घोषित किया जाता है। आप या तो स्पष्ट रूप से टेम्पलेट का नाम अर्हता या जोड़ सकते हैं:

using namespace __gnu_cxx; 
8

<unordered_map> का उपयोग करें। हैश_मैप एक विक्रेता विशिष्ट एक्सटेंशन था, जिसे unordered_map द्वारा प्रतिस्थापित किया गया था।

0

नाम स्थान __gnu_cxx उपयोग करते हुए; संकलन त्रुटि हटा दी।

का उपयोग कर

#include <hash_map> 

यह चेतावनी देता है और दूर करने

#include <hash_map> 

g++ listcheck.cc 
listcheck.cc: In function ‘int main()’: 
listcheck.cc:20: error: ‘hash_map’ was not declared in this scope 
listcheck.cc:20: error: expected primary-expression before ‘const’ 
listcheck.cc:20: error: expected ‘;’ before ‘const’ 
listcheck.cc:21: error: ‘months’ was not declared in this scope 
हटाने के बाद एक संकलन त्रुटि

In file included from /usr/include/c++/4.4/backward/hash_map:59, 
       from listcheck.cc:6: 
/usr/include/c++/4.4/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. 

देता है

संबंधित मुद्दे