我試圖用std :: function和std :: bind綁定方法時遇到問題。綁定std ::函數錯誤
在我CommunicationService類:
this->httpServer->BindGET(std::bind(&CommunicationService::ManageGETRequest, this, std::placeholders::_1));
CommunicationService :: ManageGetRequest簽名:
MessageContent CommunicationService::ManageGetRequest(std::string uri, MessageContent msgContent)
BindGET簽名:
void RESTServer::BindGET(RequestFunction getMethod)
RequestFunction的typedef:
typedef std::function<MessageContent(std::string, MessageContent)> RequestFunction;
上BindGET錯誤:
錯誤C2664: '無效 RESTServer :: BindGET(RequestFunction)': 不能從 「的std :: _粘結劑<的std :: _非受迫性,在messageContent轉換參數1( __cdecl 通信:: CommunicationService :: * )(的std :: string,在messageContent),通信:: CommunicationService * const的,常量性病:: _博士< 1> &>」到 'RequestFunction'
之前,我RequestFunction是這樣的:
typedef std::function<void(std::string)> RequestFunction;
它完美地工作。 (當然,所有簽名方法都會進行調整)。
我不明白是什麼導致了錯誤。
'ManageGetRequest'接受兩個參數加'this'。你只給這個''綁定''和一個參數。 – NathanOliver
你錯過了一個'_2'。 – Barry
好的,謝謝,我應該更仔細地查看文檔,我不明白std :: bind如何實際工作 – Morgan