std :: functionとstd :: bindでメソッドをバインドしようとすると問題が発生します。私CommunicationServiceクラスでBind std :: function error
:
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上のエラー:
「を' __cdecl 通信:: CommunicationService :: * )(スタンダード::文字列、MessageContent)、通信:: CommunicationService * CONST、CONSTはstd :: _ Phで< 1> &>エラーC2664: '無効 RESTServer :: BindGET(RequestFunction)': は 「のstd :: _バインダー<のstd :: _凡、MessageContentから引数1を変換することはできません( RequestFunction '
前に、私のRequestFunctionはそのようなものだった:
typedef std::function<void(std::string)> RequestFunction;
、それが完全に働きました。 (すべての署名方法はもちろん調整されています)。
エラーの原因を理解できません。
this->httpServer->BindGET(
[this](std::string uri, MessageContent msgContent) {
this->ManageGETRequest(std::move(uri), std::move(msgContent));
}
);
へ
'ManageGetRequest'は2つのパラメータと' this'をとります。あなたは 'bind '' this'と一つのパラメータだけを与えます。 – NathanOliver
'_2'がありません。 – Barry
ありがとう、私はドキュメントをもっと慎重に見ていたはずです、私はstd :: bindが実際に動作していた方法を理解していない – Morgan