нет соответствующей функции для вызова 'bind (, const std :: _ Placeholder <1> &, int *) - PullRequest
0 голосов
/ 20 декабря 2018
#include <functional>

template <typename T>
void TemplateFunc(const int value, T* addr) {
}

void Register(std::function<void(const int)>&& callback) {
  callback(2);
}

int main() {
  int int_value;
  Register(std::bind(&TemplateFunc, std::placeholders::_1, &int_value));
}

Не могу понять почему?

подробный журнал:

test.cpp: In function ‘int main()’:
test.cpp:13:70: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const std::_Placeholder<1>&, int*)’
   Register(std::bind(&TemplateFunc, std::placeholders::_1, &int_value));

                                                                      ^
test.cpp:13:70: note: candidates are:
In file included from test.cpp:1:0:
/usr/local/gcc4.8.2/include/c++/4.8.2/functional:1655:5: note: template<class _Func, class ... _BoundArgs> typename std::_Bind_helper<std::__or_<std::is_integral<typename std::decay<_Tp>::type>, std::is_enum<typename std::decay<_Tp>::type> >::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...)
     bind(_Func&& __f, _BoundArgs&&... __args)

1 Ответ

0 голосов
/ 20 декабря 2018

TemplateFunc - это не имя функции, вам нужно предоставить аргумент шаблона:

Register(std::bind(&TemplateFunc<int>, std::placeholders::_1, &int_value));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...