error: no match for ‘operator<' (operand types are 'const Request_Info' and 'const Request_Info')xxxxxxx

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: