Request_Info requestInfo;
requestInfo.askTYpe = askType;
requestInfo.askName = _getAskName(askType, jsonStr);
if(m_askIdMap.count(requestInfo) < 1){ //Compile this code and report an error
std::cout << "no match request:" << askType << "," << jsonStr;
}else {
}
When the std::map.count()
function is executed, the size of the key will be compared. As a custom type Request_Info
, the size comparison itself cannot be done.
<
operator overload function to the custom type, as shown below:struct Request_Info{
std::string askTYpe; //Request, success, failure
std::string askName; //SelectFilebyMultiKey, ShowRootDirectory, etc.
bool operator<(const struct Request_Info& requestInfo){
bool ret = false;
if(askName<requestInfo.askName){
ret = true;
}else if(askName == requestInfo.askName){
if(askTYpe <requestInfo.askTYpe){
ret = true;
}
}
return ret;
}
friend bool operator<(const struct Request_Info& req1, const struct Request_Info& req2){
bool ret = false;
if(req1.askName<req2.askName){
ret = true;
}else if(req1.askName == req2.askName){
if(req1.askTYpe <req2.askTYpe){
ret = true;
}
}
return ret;
}
};