簡體   English   中英

Windows到Linux端口C ++錯誤

[英]Windows to Linux port c++ errors

我正在努力將大型的c ++應用程序從Windows移植到Linux,到目前為止,我一直在研究這些問題,並用標准代碼替換Windows特定的東西。

我遇到了一個像這樣的模板

#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'class base_type'”。 顯然有一些目的,並且Microsoft編譯器必須允許它。

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

error: prototype for ‘typename intrusive_ptr<object_type, base_type>::object_type& intrusive_ptr<object_type, base_type>::operator*() const’ does not match any in class ‘intrusive_ptr<object_type, base_type>’

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

我不是最精通c ++的人,因為它不是我的主要語言,但是到目前為止,通過嘗試此端口我已經學到了很多東西,並且還將繼續學習很多東西。 目前,我對這些錯誤有些困惑,希望有人可以提供幫助。

謝謝。

base_typetypedef非常簡單:要使模板參數列表中使用的類型對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;
    // ...

我認為這也可以解決重載問題:似乎找不到正確的重載的問題是未定義嵌套類型的后續問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM