What is wrong here?

Discussion in 'C++' started by peter_k, Nov 11, 2005.

  1. peter_k

    peter_k Guest

    #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;
    }
    peter_k, Nov 11, 2005
    #1
    1. Advertising

  2. peter_k wrote:
    > #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
    Victor Bazarov, Nov 11, 2005
    #2
    1. Advertising

  3. peter_k

    Ron Natalie Guest

    peter_k wrote:
    > #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.
    Ron Natalie, Nov 11, 2005
    #3
  4. peter_k

    Neil Cerutti Guest

    On 2005-11-11, peter_k <> wrote:
    > 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.

    --
    Neil Cerutti
    Neil Cerutti, Nov 11, 2005
    #4
  5. Neil Cerutti wrote:
    > On 2005-11-11, peter_k <> wrote:
    > > 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
    Jonathan Mcdougall, Nov 11, 2005
    #5
  6. peter_k

    Neil Cerutti Guest

    On 2005-11-11, Jonathan Mcdougall <> wrote:
    >
    > Neil Cerutti wrote:
    >> On 2005-11-11, peter_k <> wrote:
    >> > 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.

    --
    Neil Cerutti
    Neil Cerutti, Nov 11, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Hester

    Try over here likely more to the point here

    George Hester, Sep 30, 2004, in forum: Javascript
    Replies:
    0
    Views:
    98
    George Hester
    Sep 30, 2004
  2. FAQ server
    Replies:
    0
    Views:
    137
    FAQ server
    Aug 10, 2006
  3. FAQ server
    Replies:
    0
    Views:
    118
    FAQ server
    Oct 7, 2006
  4. FAQ server
    Replies:
    0
    Views:
    133
    FAQ server
    Dec 4, 2006
  5. FAQ server
    Replies:
    7
    Views:
    119
    Dr J R Stockton
    Feb 10, 2007
Loading...

Share This Page