This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ help, please? (fwd)


Hi,

I got this. Is this an egcs bug or is the code bogus?

Thanks.

H.J.
---
I'm having a weird trouble with egcs-1.1.1 using STL stuff.
It may well be that I'm doing something wrong -  but maybe
you can spot it, as I can't. I spent the whole last night
trying to figure out what the f*** is wrong with the code
I've written - to no avail. If you could shed ANY light
on my problem(s), I'd he happy!  Thank you!

Here's the code:

#include <hash_map>

typedef const unsigned char ByteKeyID[8];

struct kcmp {
  bool operator() (ByteKeyID a, ByteKeyID b) const {
    return (memcmp(a, b, 8) == 0);
  }
};

typedef hash_map<ByteKeyID, 
  int, 
  hash<ByteKeyID>, 
  kcmp> 
hmap;

int main(int argc, char **argv)
{
  int i=0;
  ByteKeyID kid;
  hmap hm;

  for (i = 0; i < 8; i++) kid[i] = 8-i;
  hm.insert(kid, 2);

  for (i = 0; i < 8; i++) kid[i] = i;
  hm.insert(kid, 10);

  for (i = 0; i < 8; i++) kid[i] = 8-i;

  cout << "Extracted first value: ";
  cout << hm[kid] << endl;
}

Here's what the compiler says:

uri@alisan:/usr2/src/crypto-3.0 > g++ -I. -g -o v2-t v2-t.cc
/usr/include/g++-2/stl_hash_map.h: In instantiation of `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
v2-t.cc:21:   instantiated from here
/usr/include/g++-2/stl_hash_map.h:78: new declaration `hash_map<unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<>()'
/usr/include/g++-2/stl_hash_map.h:78: ambiguates old declaration `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()'
/usr/include/g++-2/stl_hash_map.h: In method `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
/usr/include/g++-2/stl_hash_map.h:78: confused by earlier errors, bailing out
uri@alisan:/usr2/src/crypto-3.0 > g++ -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.60.1/specs
gcc version egcs-2.91.60.1 19990115/Linux (egcs-1.1.1 release)
uri@alisan:/usr2/src/crypto-3.0 > 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]