bind shared_ptr::reset - 未找到匹配的重载函数

bind shared_ptr::reset - no matching overloaded function found

以下代码片段在 Visual Studio 2005(使用 boost 1.34)中有效,但无法在 Visual Studio 2015(使用 boost 1.62)中编译,表示 "error C2672: 'boost::bind': no matching overloaded function found"

我是不是漏掉了什么?

谢谢!

typedef boost::shared_ptr< int > SProxySharedPtr;
SProxySharedPtr    m_sptr_proxy;

auto a = boost::bind(&SProxySharedPtr::reset, &m_sptr_proxy);

我尝试使用 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);
}

boost::shared_ptr<.>::reset() 是一个重载的成员函数。因此,您必须明确指定要使用的重载:

auto a = boost::bind(static_cast<void(SProxySharedPtr::*)()>(&SProxySharedPtr::reset), &m_sptr_proxy);