首页 > 解决方案 > 我有错误它的含义:错误 C2440 'return': cannot convert from 'void (__cdecl &)(yield_context)' to 'void (&)(yield_context)'

问题描述

我正在制作程序,在该程序中我尝试制作 boost packaged_task,然后将其未来放入向量中并使用 asio post 启动它。
当我尝试制作 packaged_task 时,它给了我这个错误:

Error   C2440   'return': cannot convert from 'void (__cdecl &)(boost::asio::yield_context)' to 'void (&)(boost::asio::yield_context)'  

这是相关代码:

typedef boost::packaged_task<std::string(boost::asio::yield_context)>  task_t;
        boost::shared_ptr<task_t> task = boost::make_shared<task_t>(boost::bind(&HTTPRequest::Execute, mClientRequestsVariables[m_HttpClient_request_name]->shared_from_this() , boost::placeholders::_1, m_HttpClient_request_name, Get_mHTTPClient_Responses_Map_shared_pointer()));
        boost::future<std::string> fut = (task->get_future());
        mPendingData.push_back(std::move(fut)); // C++11 possible: (std::move(fut) when fut is a unique_future);        
        mIos.post(boost::bind(&task_t::operator(), task));

这是 HTTPRequst::Execute 的定义:

HTTPRequest::HTTPRequest(boost::asio::io_service& ios, unsigned int id, std::string URL, const HTTPServiceResolve& resolve_addr, boost::shared_ptr<LoggingClass_2> mHTTPRequest_LoggingInstance_shared_pointer) 

并且 HTTPRequest 类派生自 enable_shared_from_this 。

错误在 bind.hpp 中,所以我在 vs 输出窗口中找到了包含代码部分的线索。

为什么会发生这个错误?解决方案是什么?

标签: boost-asioboost-bindpackaged-task

解决方案


推荐阅读