绑定 shared_ptr::reset - 找不到匹配的重载函数
Posted
技术标签:
【中文标题】绑定 shared_ptr::reset - 找不到匹配的重载函数【英文标题】:bind shared_ptr::reset - no matching overloaded function found 【发布时间】:2016-12-31 00:24:41 【问题描述】:以下代码 sn-p 在 Visual Studio 2005(使用 boost 1.34)中工作,但在 Visual Studio 2015(使用 boost 1.62)中编译失败,说“错误 C2672:'boost::bind':没有匹配的重载函数找到”
我错过了什么吗?
谢谢!
typedef boost::shared_ptr< int > SProxySharedPtr;
SProxySharedPtr m_sptr_proxy;
auto a = boost::bind(&SProxySharedPtr::reset, &m_sptr_proxy);
【问题讨论】:
可以分享SProxySharedPtr::reset
函数吗?可以不带参数调用吗?
感谢您的及时回复:)
SProxySharedPtr 是 typedef ( typedef boost::shared_ptr SProxySharedPtr;)。所以它本质上与 boost::shared_ptrboost::shared_ptr<.>::reset()
是一个重载的成员函数。因此,您必须明确指定要使用的重载:
auto a = boost::bind(static_cast<void(SProxySharedPtr::*)()>(&SProxySharedPtr::reset), &m_sptr_proxy);
【讨论】:
我明白了。非常感谢你!! (我想知道它之前是如何工作的:))对于那些遇到这个问题的人,请参阅boost.org/doc/libs/1_62_0/libs/bind/doc/html/…【参考方案2】:我尝试使用 GCC,但看到了类似的错误。我可以编译它的唯一方法是子类 boost::shared_ptr 如下(但也许这不是你想要的):
typedef boost::shared_ptr<int> SProxySharedPtr;
struct Bar : SProxySharedPtr
void reset()
SProxySharedPtr::reset();
;
int main()
const Bar m_sptr_proxy;
boost::bind(&Bar::reset, &m_sptr_proxy);
【讨论】:
以上是关于绑定 shared_ptr::reset - 找不到匹配的重载函数的主要内容,如果未能解决你的问题,请参考以下文章
apache tomcat 7.0.30 datasourcerealm javax.naming.NameNotFoundException:名称 [jdbc/proto] 未绑定在此上下文中。找不