【问题标题】:compiler error for shared_ptr in Visual Studio 2010Visual Studio 2010 中 shared_ptr 的编译器错误
【发布时间】:2011-11-26 17:55:43
【问题描述】:

将项目从 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

这是 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;
}

我设置了一个类似但不太复杂的项目,但没有遇到同样的错误。

【问题讨论】:

  • 您能否提供将 r 值分配给某种 shared_ptr 的代码,并提供所涉及的类型。
  • shared_ptr 到处都是,我会检查所有的作业,看看我是否弄错了

标签: c++ visual-studio boost shared-ptr


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多