代码之家  ›  专栏  ›  技术社区  ›  hinewwiner

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

  •  0
  • hinewwiner  · 技术社区  · 8 年前

    以下代码片段在Visual Studio 2005(使用boost 1.34)中工作,但在Visual Studio 2015(使用Boost1.62)中编译失败,表示“错误C2672:'boost::bind':未找到匹配的重载函数”

    我是不是遗漏了什么?

    非常感谢。

    typedef boost::shared_ptr< int > SProxySharedPtr;
    SProxySharedPtr    m_sptr_proxy;
    
    auto a = boost::bind(&SProxySharedPtr::reset, &m_sptr_proxy);
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   O'Neil    8 年前

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

    auto a = boost::bind(static_cast<void(SProxySharedPtr::*)()>(&SProxySharedPtr::reset), &m_sptr_proxy);
    
        2
  •  0
  •   volatilevar    8 年前

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