How to make map with two kwys. I am using struct.

struct Key
{
    char * gi;
    char * offset;
    Key(const char * _gi, const char * _offset)
    {
        gi = new char [strlen(_gi) + 1];
        strcpy(gi, _gi);
        offset = new char [strlen(_offset) + 1];
        strcpy(offset, _offset);
    }
    ~Key()
    {
        if (gi != NULL)
        {
            delete [] gi;
            gi = NULL;
        }
        if (offset != NULL)
        {
            delete [] offset;
            offset = NULL;
        }
    }
};
struct Value
{
    char * orient;
 char * allele ;
    Value(const char * _orient, const char * _allele)
    {
        orient = new char [strlen(_orient) + 1];
        strcpy(orient, _orient);
        allele = new char [strlen(_allele) + 1];
        strcpy(allele, _allele);
    }
    ~Value()
    {
        if (orient != NULL)
        {
            delete [] orient;
            orient = NULL;
        }
        if (allele != NULL)
        {
            delete [] allele;
            allele = NULL;
        }
    }
};

struct ltstr
{
    bool operator()(const Key* _lhs, const Key* _rhs) const
    {
        return (strcmp(_lhs->gi,_rhs->gi) > 0 && strcmp(_lhs->offset,_rhs->offset) );
  }
};
Key key ("34", "abcd");
Value value ("sdf", "asdf");
n.insert(dbmap::value_type(&key,&value));

When i try to retrieve the keys and values using iterator to map, i am not getting anything.
Can you tell me where i am wrong?
I will be really thankful if you can help me.

Regards
Man

1. Use code tag:
[code=c++] source

[/code]
2. As usually, such classes as Key and Value need user-defined copy constructors and overloaded assignment operators. Default ctor and operator= (member by member) are wrong.
3. What's your class dbmap definition? If it's std::map<Key*,Value*> then you can't get sensible map for Key* type key (operator< for pointers used). Besides that, std::map has a single key by definition (see a strange title of your post == I want hot ice). Probably you must define Key::operator< and define std::map<Key,Value> map.

1. Use code tag:
[code=c++] source

[/code]
2. As usually, such classes as Key and Value need user-defined copy constructors and overloaded assignment operators. Default ctor and operator= (member by member) are wrong.
3. What's your class dbmap definition? If it's std::map<Key*,Value*> then you can't get sensible map for Key* type key (operator< for pointers used). Besides that, std::map has a single key by definition (see a strange title of your post == I want hot ice). Probably you must define Key::operator< and define std::map<Key,Value> map.

My map is map<Key*,value*,ltstr> . Since i am using comparator so it should work.
Still not able to understand the pblm.

It's impossible to understand the problem in your snippet. At first present the code fragment with the problem...
Apropos, it's not "a map with two keys". It's a compound key, that's all...

I understand a map with 2 keys being a 2d map array?
map<Key, Map<Key, Value> > So i suppose you can do that if you want a value that uses two keys to make it unique?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.