code:
Request_Info requestInfo; requestInfo.askTYpe = askType; requestInfo.askName = _getAskName(askType, jsonStr); if(m_askIdMap.count(requestInfo) < 1){ //error std::cout << "no match request:" << askType << "," << jsonStr; }else { }
Cause analysis:
When the STD:: map.Count() function is executed, the size of the key will be compared as a user-defined type request_Info itself cannot be used for size comparison.
Solution:
1. Change a type capable of size comparison to make the key value of map.
2. Add < Operator overloads the function as follows:
struct Request_Info{ std::string askTYpe; // std::string askName; //SelectFilebyMultiKey,ShowRootDirectory 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; } };
Similar Posts:
- [Solved] Operator overload must take either zero or one argument error
- [LeetCode] 291. Word Pattern II
- How to Solve JAVA Error: “error: bad operand types for binary operator ”
- [Solved] Error: error c2678: binary ‘<', no left operand operator (or no acceptable conversion) that accepts type 'const a' was found
- How to solve the infinite loop of react. Useeffect()?
- [swscaler @ …] deprecated pixel format used, make sure you did set range correctly
- [leetcode] 140. Word break II word split II
- C++ error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m…
- How to Solve Datatable field value is empty Error
- How to Use awk to Analyze Nginx Log