Example:

#include<iostream>

using namespace std;

enum e_UserName
{
   planet1,
   planet2,
   planet3,
   planet4,
   planet5,
   planet6,
   planet7
};

enum e_ServerName1
{
   Venus = 11,
   Mars,
   earth
};

enum e_ServerName2
{
   jupiter = 11,
   pluto,
   neptune,
   earth2
};


struct map
{
   enum e_UserName eUserName;
   enum e_ServerName eServerName;
};

struct map name[] = {   {planet1,(e_ServerName) Venus},
                        {planet2, (e_ServerName)Mars},
                        {planet3, (e_ServerName)earth},
                        {planet4, (e_ServerName)jupiter},
                        {planet5, (e_ServerName)pluto},
                        {planet6, (e_ServerName)neptune},
                        {planet7, (e_ServerName)earth2}
                     };


int main()
{

   for(int i=0; i<7; i++)
   {
      cout<<name[i].eUserName<<"is = "<<name[i].eServerName<<endl;
   }

   for(int i=0; i<3; i++)
   {
      if (name[i].eUserName == planet2)
      {
         cout<<"Server Name = "<<name[i].eServerName<<endl;
         break;
      }
   }
   return 0;
}


Now I will go with the requirement as follows;

There is one enum "e_UserName" at one end having values b/n  0 -to- 6.

At the other and we have two different enums "e_ServerName2" (0 - 2) and "e_ServerName1" (0 - 3).

Now and i need to map below two eums with the above enum "e_UserName".

Secondly,

I will get the values of "e_ServerName2" (0 - 2) and "e_ServerName1" (0 - 3)  as INPUT to my Function() and

I need to Return the respective enum "e_UserName"  values from that function.



Could you please let me know how can i do this (logic).

Also if any Features in C++ that can support this requirement is also OK. (C++ Libraries using MAP or other).

Thanks well in Adwance

`**

Use std::map<> with
std::pair< e_ServerName1, e_ServerName2 > as the key_type
and e_UserName as the mapped_type.
http://en.cppreference.com/w/cpp/container/map

#include <map>

enum e_UserName { one, two, three, four /* etc. */ } ;

enum e_ServerName1 { Venus, Mars, Earth } ;

enum e_ServerName2 { Jupiter, Pluto, Neptune, Saturn } ;

int main()
{
    std::map< std::pair< e_ServerName1, e_ServerName2 >, e_UserName > look_up ;
    look_up[ std::make_pair(Venus,Pluto) ] = three ;
    look_up[ std::make_pair(Earth,Jupiter) ] = one ;
    // etc

    e_ServerName1 a = Earth ;
    e_ServerName2 b = Jupiter ;
    auto iter = look_up.find( std::make_pair(a,b) ) ;
    if( iter != look_up.end() ) // found it
    {
        e_UserName user_name = iter->second ;
        // do whatever with user_name
    }
}

Thank you very much. Let me try this out as I am new to "map".

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.