tags:

views:

102

answers:

3

i am trying to implement hash_multimap in c++ here is code

  #include <hash_map>
#include<iostream>
#include <string>
#include <hashtable.h>
#include <hash_set>

#include <stdlib.h>
#include <stdio.h>
struct eqstr{
    bool operator()(const char *s1,const char* s2)const{
        return strcmp(s1,s2)==0;
    }

};

typedef hash_multimap<const char*, int, hash<const char*>, eqstr> map_type;


int main() {


    return (EXIT_SUCCESS);
}

but here is mistake

usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/david/NetBeansProjects/hash_multimap'
/usr/bin/make  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/hash_multimap
make[2]: Entering directory `/home/david/NetBeansProjects/hash_multimap'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++    -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
                 from main.cpp:1:
In file included from /usr/include/c++/4.4/backward/hash_map:60,
/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.
main.cpp: In member function ‘bool eqstr::operator()(const char*, const char*) const’:
main.cpp:10: error: ‘strcmp’ was not declared in this scope
main.cpp: At global scope:
main.cpp:15: error: expected initializer before ‘<’ token
make[2]: *** [build/Debug/GNU-Linux-x86/main.o] Error 1
make[2]: Leaving directory `/home/david/NetBeansProjects/hash_multimap'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/david/NetBeansProjects/hash_multimap'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)

please help

+2  A: 

First off, if you're using strcmp you need to include <string.h>.

Secondly, you might need to find out where hash_multimap is defined. It's not part of the C++ std namespace. For example, using g++ you might want to try:

using namespace __gnu_cxx;

notfed
yes but this is not problem so why downvote?
(FYI: I didn't do the downvoting)
notfed
You could also use <cstring>, which puts `strcmp` into the `std` namespace.
Thomas Matthews
+2  A: 

The problems seem pretty straightforward.

  • 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.

Track down the deprecated header, and look for upgraded packages, libraries, etc. Otherwise, hand-edit the code to update the deprecated header.

  • main.cpp: In member function ‘bool eqstr::operator()(const char*, const char*) const’: main.cpp:10: error: ‘strcmp’ was not declared in this scope

Declare it. Probably by including string.h

  • main.cpp:15: error: expected initializer before ‘<’ token

A bit less clear, but will probably become clearer as you fix earlier problems. Track down exactly which < is creating the error, and begin carefully reviewing the definitions of hash_multimap and hash

Where exactly are you having problems?

abelenky
A: 

Change this line:

#include <string>

to this:

#include <string.h>
JBRWilkinson