Of course it is possible. However you have to use a
std::map<string, Chassis>
, in other word the same map cannot hold at the same time objects of unrelated types like
Chassis
and
Manager
.
[update]
Code sample:
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct Chassis
{
string inLED;
string astTg;
};
int main()
{
map <string, Chassis> mc;
mc["Chassis1"] = { "On", "null"};
mc["Chassis2"] = { "Off", "null"};
mc["Chassis3"] = { "On", "null"};
cout << "list of chassis: " << endl;
for (const auto & c : mc) cout << c.first << " {" << c.second.inLED << ", " << c.second.astTg << "}" << endl;
string s = "Chassis1";
cout << endl << "searching for item '" << s << "'" << endl;
auto it = mc.find(s); if ( it != mc.end())
cout << "found " << it->first << " {"<< it->second.inLED << ", " << it->second.astTg << "}" << endl;
}
[/update]