gpt4 book ai didi

c++ - 没有匹配函数来调用'bind(<未解析的重载函数类型>, const std::_Placeholder<1>&, int*)

转载 作者:行者123 更新时间:2023-11-28 04:27:50 25 4
gpt4 key购买 nike

#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)

最佳答案

TemplateFunc 不是您需要提供模板参数的函数名称:

Register(std::bind(&TemplateFunc<int>, std::placeholders::_1, &int_value));

关于c++ - 没有匹配函数来调用'bind(<未解析的重载函数类型>, const std::_Placeholder<1>&, int*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53861964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com