Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Map with key as structure (http://www.go4expert.com/forums/map-key-structure-t16484/)

man4ish 10Mar2009 08:57

Map with key as structure
 
How to make map with two kwys. I am using struct.
Code:

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


All times are GMT +5.5. The time now is 16:10.