Overload vector subscript operator to take a char * or string
问题 I am trying to overload the subscript operator -i know it as the element access operator- to take a char * or a std::string. I have a struct struct foo { int Age; const char *Name; }; and a std::vector that will be holding multiple instances of this struct. std::vector<foo>bar; my goal is to be able to access each foo in bar by calling them by their name. std::cout<<"Simon's age is: "<<bar["simon"]; I've just been searching google for a long while trying to find an example or something to go