tags:

views:

123

answers:

2

i have following code

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <hash_map>
#include <string>
#include <iterator>
#include <ostream>
using namespace std;
struct Equal
{

    bool operator()(const char *s1,const char *s2)const
        {
            return std::strcmp(s1,s2)==0;
        }

};
    typedef std::hash_multimap<const char*,int,hash<const char*>,Equal>map_type;
    void lookup(const map_type&Map,const char *str){
        cout<<str<<":";
        pair<map_type::const_iterator ,map_type::const_iterator>p=Map.equal_range(str);
        for (map_type::const_iterator i=p.first;i!=p.second;++i)
            cout << (*i).second<<" ";



    }
int maain(){

    map_type m;
    m.insert(map_type::value_type("H", 1));
 m.insert(map_type::value_type("H", 2));
 m.insert(map_type::value_type("C", 12));
  m.insert(map_type::value_type("C", 13));
  m.insert(map_type::value_type("O", 16));
  m.insert(map_type::value_type("O", 17));
  m.insert(map_type::value_type("O", 18));
  m.insert(map_type::value_type("I", 127));
  lookup(M,"I");
  lookup(M,"0");
  lookup(M,"Rn");


    return 0;
}

but here is errors

1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2903: 'rebind' : symbol is neither a class template nor a function template
1>          c:\program files\microsoft visual studio 10.0\vc\include\xhash(170) : see reference to class template instantiation 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled
1>          with
1>          [
1>              _Kty=const char *,
1>              _Ty=int,
1>              _Tr=std::hash<const char *>,
1>              _Alloc=Equal,
1>              _Mfl=true
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\hash_map(273) : see reference to class template instantiation 'std::_Hash<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Hmap_traits<const char *,int,std::hash<const char *>,Equal,true>
1>          ]
1>          c:\users\7\documents\visual studio 2010\projects\hash_tables\hash_tables\hash_tables.cpp(22) : see reference to class template instantiation 'stdext::hash_multimap<_Kty,_Ty,_Tr,_Alloc>' being compiled
1>          with
1>          [
1>              _Kty=const char *,
1>              _Ty=int,
1>              _Tr=std::hash<const char *>,
1>              _Alloc=Equal
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2039: 'rebind' : is not a member of 'Equal'
1>          c:\users\7\documents\visual studio 2010\projects\hash_tables\hash_tables\hash_tables.cpp(11) : see declaration of 'Equal'
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2143: syntax error : missing ';' before '<'
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2039: 'other' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(27): error C2238: unexpected token(s) preceding ';'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(180): error C2039: 'bucket_size' : is not a member of 'std::hash<_Kty>'
1>          with
1>          [
1>              _Kty=const char *
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(180): error C2065: 'bucket_size' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2039: 'allocator_type' : is not a member of 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>'
1>          with
1>          [
1>              _Kty=const char *,
1>              _Ty=int,
1>              _Tr=std::hash<const char *>,
1>              _Alloc=Equal,
1>              _Mfl=true
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2146: syntax error : missing ',' before identifier 'allocator_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2065: 'allocator_type' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(186): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(187): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(188): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(189): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(190): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(191): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(192): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(193): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(197): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2955: 'std::list' : use of class template requires template argument list
1>          c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2146: syntax error : missing ';' before identifier 'iterator'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C3254: 'std::_Hash<_Traits>' : class contains explicit override 'type' but does not derive from an interface that contains the function declaration
1>          with
1>          [
1>              _Traits=std::_Hmap_traits<const char *,int,std::hash<const char *>,Equal,true>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2838: 'type' : illegal qualified name in member declaration
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2208: 'std::iterator' : no members defined using this type
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.96
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

please help

+5  A: 

You have to look at each complier error and fix them one at a time. We can't take a file of code and fix each error. Learning to live and even on occasion love the abusive spouse that is your complier is part of the process.

rerun
Especially when multiple lines of seemingly indecipherable and unrelated errors result from a single missing semicolon. :-)
Konrad
Deciphering template errors is an aquired skill and the poster seems to be new to C++. At least, pointing out the relevant parts of the error message might help him/her out for the next compiler vomit he/she comes accross!
André Caron
+3  A: 

All your errors seem related to the fact that you're not passing the right template arguments to hash_multimap. Take a look at hash_multimap's documentation. The last parameter, Èqual` should be the allocator, not a function object, check out the 1st error:

c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2903: 'rebind' : symbol is neither a class template nor a function template c:\program files\microsoft visual studio 10.0\vc\include\xhash(170) : see reference to class template instantiation 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled with [ _Kty=const char *, _Ty=int, _Tr=std::hash, _Alloc=Equal, _Mfl=true ]

Edit:

If you've looked at SGI's hash_multimap documentation, you'll notice that the hash_map and hash_multimap classes are different between vendors because they are not standard. The next version of the standard comprises standard hashed containers. In the mean time, well, you'll have to write non portable code!

André Caron