What is wrong here?

P

peter_k

#include <cstdlib>
#include <iostream>
#include <hash_map.h>

using namespace std;

typedef struct {
unsigned long data[3];
} sKey, tKey;

typedef struct {
unsigned char value;
} sValue, tValue;

namespace __gnu_cxx {
template<>
struct hash<tKey> {
size_t operator()(const tKey &d) const {
return d.data[0];
};
};
};

int main(int argc, char *argv[])
{
hash_map<tKey, tValue, hash<tKey> > dane;

tKey key;
tValue value;
key.data[0] = 13;
key.data[1] = 0;
key.data[2] = 0;
value.value = 15;

dane[key] = value; // here something is wrong :(

system("PAUSE");
return EXIT_SUCCESS;
}
 
V

Victor Bazarov

peter_k said:
#include <cstdlib>
#include <iostream>
#include <hash_map.h>
[..]
> hash_map<tKey, tValue, hash<tKey> > dane;
> [..]
> dane[key] = value; // here something is wrong :(
> [..]

'<hash_map.h>' is a non-standard header, and 'hash_map' is a non-standard
template, you should consider asking in a newsgroup for the product that
provides that header (assuming that there is one). Otherwise, provide the
entire contents of that header (and all others that it includes). Without
it I cannot take your code and try to compile it to see what it is
"something" that is "wrong". Also read the FAQ 5.8.

V
 
R

Ron Natalie

peter_k said:
#include <cstdlib>
#include <iostream>
#include <hash_map.h>

using namespace std;

hash_map is a nonstandard concept and the problem almost
certainly lies there.

I suspect the major issue is that hash_map requires some sort
of equality (or other relation) key that you haven't defined.
 
N

Neil Cerutti

int main(int argc, char *argv[])
{
hash_map<tKey, tValue, hash<tKey> > dane;

Here something is probably wrong, as hash_map is likely hoping
for type names, not instances. But it's impossible to say for
sure without the definition of the hash_map template.
 
J

Jonathan Mcdougall

Neil said:
int main(int argc, char *argv[])
{
hash_map<tKey, tValue, hash<tKey> > dane;

Here something is probably wrong, as hash_map is likely hoping
for type names, not instances. But it's impossible to say for
sure without the definition of the hash_map template.

These three names *are* types.


Jonathan
 
N

Neil Cerutti

Neil said:
int main(int argc, char *argv[])
{
hash_map<tKey, tValue, hash<tKey> > dane;

Here something is probably wrong, as hash_map is likely hoping
for type names, not instances. But it's impossible to say for
sure without the definition of the hash_map template.

These three names *are* types.

Thanks for the correction. I didn't see the typedef keyword
sitting there in front of my nose and thought they were anonymous
structures.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top