2015-03-24 28 views
2

我正在將大型C++應用程序從Windows移植到Linux,到目前爲止,我一直在解決這些問題,並用標準代碼替換Windows特定的東西。Windows到Linux端口的C++錯誤

我遇到的是這樣開始的

#define IC __attribute__((inline)) 

template <typename object_type, typename base_type = intrusive_base> 
class intrusive_ptr 
{ 
private: 
    typedef base_type base_type; 
    typedef object_type object_type; 
    typedef intrusive_ptr<object_type, base_type> self_type; 
    typedef const object_type* (intrusive_ptr::*unspecified_bool_type)() const; 

... 

public: 
    IC intrusive_ptr(); 
    IC intrusive_ptr(object_type* rhs); 
    IC intrusive_ptr(self_type const& rhs); 
    IC ~intrusive_ptr(); 
    IC self_type& operator= (object_type* rhs); 
    IC self_type& operator= (self_type const& rhs); 
    IC object_type& operator*() const; // original 
    IC object_type* operator->() const; // original 

... 
}; 


#define TEMPLATE_SPECIALIZATION template <typename object_type, typename base_type> 
#define _intrusive_ptr intrusive_ptr<object_type, base_type> 

TEMPLATE_SPECIALIZATION 
IC typename _intrusive_ptr::object_type& _intrusive_ptr::operator*() const 
{ 
    VERIFY(m_object); 
    return (*m_object); 
} 

TEMPLATE_SPECIALIZATION 
IC typename _intrusive_ptr::object_type* _intrusive_ptr::operator->() const 
{ 
    VERIFY(m_object); 
    return (m_object); 
} 

我無法理解一些事情的模板。

什麼是對

typedef base_type base_type; 

的原因GCC有問題吧,因爲它「陰影模板的parm‘類base_type’」。顯然,它有一些目的,Microsoft編譯器必須允許它。

我也有下面給出錯誤的TEMPLATE_SPECIALIZATION東西之類的問題

&

error: candidate is: object_type& intrusive_ptr<object_type, base_type>::operator*() const 

我不是最精通C++,因爲它不是我的主要語言,但我有通過嘗試這個港口瞭解了很多,並將繼續學習很多。我現在有點卡住了這些錯誤,並希望有人能夠提供幫助。

謝謝。

回答

3

typedefbase_type很簡單:要在提供給的intrusive_ptr用戶(雖然,因爲類型實際上是「私人」它並沒有真正太大意義),類型爲模板參數列表中使用的類型在模板定義中定義。瑣碎的解決方法是修改代碼,成爲

template <typename Object_type, typename Base_type = intrusive_base> 
class intrusive_ptr 
{ 
private: 
    typedef Base_type base_type; 
    typedef Object_type object_type; 
    // ... 

我覺得還修復了超負荷的問題:它似乎有沒有找到正確的過載問題是嵌套式的後續問題沒有被定義。

+0

謝謝。我知道它會歸結爲簡單。我很感激幫助。 – Tim 2015-03-24 22:48:12