A Map with both key and value as Struct

Joined
Feb 3, 2009
Messages
1
Reaction score
0
Hi,

I am trying to develop one requirement wherein I need a C++ map having both Key and Value as Structures.

The structures are as follows:

typedef struct _keyInfo
{
int Key1;
int Key2;
} T_KeyInfo, * T_pKeyInfo;

typedef struct _valueInfo
{
int value1;
int value2;
int value3;
} T_ValueInfo, * T_pValueInfo;

and my map is:

typedef map<T_pKeyInfo, T_pValueInfo> T_Map, * T_pMap;

I tried to insert one row into this map using the insert command:

M_pMap->insert(T_Map::value_type(L_pKey,L_pValue));

and Later I am trying to retrive the stored values in the map using find command

T_Map::iterator L_iterator;
T_pKeyInfo L_pKey = NULL;
T_pValueInfo L_pValue = NULL;

L_iterator = M_pMap->find(T_Map::key_type(L_pKey));
if (L_iterator != M_pMap->end())
{
L_pValue = L_iterator->second;
int P_Result=L_pValue->value1;
}

Somehow I am not able to retrive the value1 from the map using the above code.

Can anyone please help me in resolving this issue.
It will be OK, if any better approach/procedure exists to have a map with key and value as structs.

Thanks in advance...............
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top