c++ - std::bind() error: cannot determine which instance of overloaded function "boost::asio::io_service::run" is intended -


while trying compile in visual c++ 2015

  auto worker = std::bind(&boost::asio::io_service::run, &(this->service)); 

i'm getting errors:

error c2783: 'std::_binder<_ret,_fx,_types...> std::bind(_fx &&,_types &&...)': not deduce template argument '_ret' note: see declaration of 'std::bind'  error c2783: 'std::_binder<_ret,_fx,_types...> std::bind(_fx &&,_types &&...)': not deduce template argument '_fx' note: see declaration of 'std::bind'  error c2783: 'std::_binder<std::_unforced,_fx,_types...> std::bind(_fx &&,_types &&...)': not deduce template argument '_fx' note: see declaration of 'std::bind' 

additionally, intellisense complains with:

cannot determine instance of overloaded function "boost::asio::io_service::run" intended 

i see there 2 overloads of boost::asio::io_service::run. how can specify 1 use?

with boost::bind code compiles fine:

  auto worker = boost::bind(&boost::asio::io_service::run, &(this->service)); 

since boost::asio::io_service::run has 2 overloads, need specify use when using function pointer(1). needs done casting right function signature:

static_cast<std::size_t(boost::asio::io_service::*)()>(&boost::asio::io_service::run) 

since looks horrible, suggest use lambda instead of bind expression. inside lambda, normal overload resolution takes place, don't need specify overload explicitly:

auto worker = [this]{ return service.run(); }; 

(1) problem std::bind takes function unrestricted template argument, rules of template type deduction apply instead of overload resolution. c++ can't determine type of _fx should here, since pass type not specified. if there trick such c++ can try resolve overload when using fact bound arguments going passed function, note both overloads possible here: overload boost::system::error_code & ec not bound , "curried" instead (specifying value parameter delayed point when worker called).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -