2011-11-26 122 views
1

從代碼塊轉換項目到Visual Studio編譯器錯誤我遇到了這個令人費解的錯誤由編譯器:爲shared_ptr的Visual Studio 2010中

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 

下面是升壓轉換器的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; 
} 

我建立了一個類似但不太複雜的項目,並沒有得到相同的錯誤。

+1

「shared_ptr」在哪裏使用? –

+3

您能否提供代碼將r值分配給某種shared_ptr的代碼,並提供所涉及的類型。 – 111111

+0

shared_ptr遍佈各處,我會檢查所有的作業,看看我是否犯了一個錯誤 –

回答

4

您可能會嘗試交換兩個不兼容類型的shared_ptr。確保兩個shared_ptr指向相同/可轉換類型的對象。

+0

你釘了它。非常感謝。 –