简体   繁体   English

Visual Studio 2010中shared_ptr的编译器错误

[英]compiler error for shared_ptr in Visual Studio 2010

Converting a project from Codeblocks to Visual Studio I encountered this puzzling error from the compiler: 将项目从Codeblocks转换为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

Here's the code in question in boost's shared_ptr.hpp 这是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;
}

I set up a similar but less complicated project and did not get the same error. 我设置了一个类似但不太复杂的项目,并没有得到相同的错误。

You probably try to swap two shared_ptr of incompatible types. 您可能尝试交换两个不兼容类型的shared_ptr Make sure that the two shared_ptr point to objects of the same/convertible type. 确保两个shared_ptr指向相同/可转换类型的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM