shared_ptr在Visual Studio 2010中的编译错误

compiler error for shared_ptr in Visual Studio 2010

本文关键字:编译 错误 2010 Studio ptr Visual shared      更新时间:2023-10-16

将项目从coblock转换为Visual Studio我遇到了编译器的这个令人费解的错误:

Error   4   error C2228: left of '.swap' must have class/struct/union
shared_ptr.hpp
Error   3   error C2440: '<function-style-cast>' : cannot convert from
'boost::shared_ptr<T>' to 'boost::shared_ptr<T>' shared_ptr.hpp 384

下面是boost的shared_ptr.hpp

中的问题代码
template<class Y>
shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
{
    this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
    return *this;
}

我设置了一个类似但不那么复杂的项目,没有得到相同的错误。

您可能会尝试交换两个不兼容类型的shared_ptr。确保两个shared_ptr指向相同/可转换类型的对象。