boost::bind 不能处理函数重载 (error: no matching function for call to ‘bind‘)

本文讲述了作者在项目中遇到boost::bind无法处理函数重载导致编译错误的问题,通过排查发现是由于函数重载导致的。解决方案是为新增参数的函数重命名,避免bind混淆。同时,讨论了bind为何不支持重载函数的可能原因。
摘要由CSDN通过智能技术生成

🚀 优质资源分享 🚀

学习路线指引(点击解锁) 知识定位 人群定位
🧡 Python实战微信订餐小程序 🧡 进阶级 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。
💛Python量化交易实战💛 入门级 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统

前言

最近任务多、工期紧,没有时间更新博客,就水一期吧。虽然是水,也不能太失水准,刚好最近工作中遇到一个 boost::bind 的问题,花费了半天时间来定位解决,就说说它吧。

问题背景

项目中使用了 boost 的 ios_service,任务都是 post 到对应线程去执行,这样可以避免复杂的多线程同步问题,有点类似早年间 COM 的单线程套间模型。不过这就需要将接口通过 bind 封装为函数对象传递给 ios_service,之前的代码都工作正常,但我新增了一个接口后,却怎么也编译不过,报下面的错误 (超长内容,展开谨慎):

查看代码

jni/../../Task/jni/../jni/../../xxxx/jni/../xxxx_xxxxxxxxx.cpp:3414:48: error: no matching function for call to 'bind'
        xxxxxxxxxxx::instance()->getIOS().post(boost::bind(&xxxxxxxxxxxxx::create_task, 
                                               ^~~~~~~~~~~
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1907:5: note: candidate template ignored: couldn't infer template argument 'R'
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1981:5: note: candidate template ignored: couldn't infer template argument 'R'
    BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:2073:5: note: candidate template ignored: couldn't infer template argument 'F'
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_cc.hpp:57:5: note: candidate template ignored: couldn't infer template argument 'R'
 BOOST\_BIND(BOOST\_BIND\_ST R (BOOST\_BIND\_CC *f) (B1, B2, B3, B4) BOOST\_BIND\_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_mf\_cc.hpp:161:5: note: candidate template ignored: couldn't infer template argument
 'R'
 BOOST\_BIND(R (BOOST\_BIND\_MF\_CC T::*f) (B1, B2, B3) BOOST\_BIND\_MF\_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_mf\_cc.hpp:172:5: note: candidate template ignored: couldn't infer template argument
 'R'
 BOOST\_BIND(R (BOOST\_BIND\_MF\_CC T::*f) (B1, B2, B3) const BOOST\_BIND\_MF\_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_mf\_cc.hpp:184:13: note: candidate template ignored: couldn't infer template argument
 'Rt2'
 >::type BOOST\_BIND(R (BOOST\_BIND\_MF\_CC T::*f) (B1, B2, B3) BOOST\_BIND\_MF\_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_mf\_cc.hpp:196:13: note: candidate template ignored: couldn't infer template argument
 'Rt2'
 >::type BOOST\_BIND(R (BOOST\_BIND\_MF\_CC T::*f) (B1, B2, B3) const BOOST\_BIND\_MF\_NOEXCEPT, A1 a1, A2 a2, A3 a3, A4 a4)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_mf2\_cc.hpp:68:5: note: candidate template ignored: could not match
 'R (T::*)(B1, B2)' against 'boost::shared\_ptr'
 BOOST\_BIND(boost::type, R (BOOST\_BIND\_MF\_CC T::*f) (B1, B2), A1 a1, A2 a2, A3 a3)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind\_mf2\_cc.hpp:79:5: note: candidate template ignored: could not match
 'R (T::*)(B1, B2) const' against 'boost::shared\_ptr'
 BOOST\_BIND(boost::type, R (BOOST\_BIND\_MF\_CC T::*f) (B1, B2) const, A1 a1, A2 a2, A3 a3)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1875:5: note: candidate function template not viable: requires single argument
 'f', but 5 arguments were provided
 BOOST\_BIND(F f)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1883:5: note: candidate function template not viable: requires 2 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1891:5: note: candidate function template not viable: requires 3 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1899:5: note: candidate function template not viable: requires 4 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1915:5: note: candidate function template not viable: requires 6 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1923:5: note: candidate function template not viable: requires 7 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1931:5: note: candidate function template not viable: requires 8 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1939:5: note: candidate function template not viable: requires 9 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1947:5: note: candidate function template not viable: requires 10 arguments, but
 5 were provided
 BOOST\_BIND(F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1957:5: note: candidate function template not viable: requires 2 arguments, but
 5 were provided
 BOOST\_BIND(boost::type, F f)
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1868:20: note: expanded from macro 'BOOST\_BIND'
#define BOOST\_BIND bind
 ^
jni/../../Task/jni/../../../third-party/boost/include/boost/bind/bind.hpp:1965:5: note: candidate function template not viable: requires 3 arguments, but
 5 were provided
 BOOST\_BIND(b
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

[虚幻私塾】

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值