简体   繁体   English

Windows到Linux端口C ++错误

[英]Windows to Linux port c++ errors

I am working on porting a large c++ application from Windows to Linux and so far I've been working through the issues and replacing the Windows specific stuff with standards code. 我正在努力将大型的c ++应用程序从Windows移植到Linux,到目前为止,我一直在研究这些问题,并用标准代码替换Windows特定的东西。

I've come across a template that begins like this 我遇到了一个像这样的模板

#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);
}

I am having trouble understanding a couple of things. 我在理解两件事时遇到了麻烦。

What is the reason for the 是什么原因

typedef base_type base_type;

GCC has issues with it as it "shadows template parm 'class base_type'". GCC遇到了问题,因为它“阴影模板parm'class base_type'”。 Obviously there was some purpose for it and the Microsoft compiler must have allowed it. 显然有一些目的,并且Microsoft编译器必须允许它。

I also have issues with the TEMPLATE_SPECIALIZATION stuff below giving errors like 我下面的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

I am not the most proficient with c++ as it isn't my primary language but I have learned a lot so far by attempting this port and will continue to learn a lot. 我不是最精通c ++的人,因为它不是我的主要语言,但是到目前为止,通过尝试此端口我已经学到了很多东西,并且还将继续学习很多东西。 I'm a bit stuck on these errors at the moment and hope someone might be able to help. 目前,我对这些错误有些困惑,希望有人可以提供帮助。

Thanks. 谢谢。

The typedef for base_type is quite simple: to make the type used in the template argument list available to users of intrusive_ptr (although, since the type is actually 'private' it doesn't really much sense), the type is defined with in the template definition. base_typetypedef非常简单:要使模板参数列表中使用的类型对intrusive_ptr用户可用(尽管由于该类型实际上是“私有的”,实际上并没有多大意义),所以该类型在模板定义。 The trivial fix is to change the code to become 简单的解决方法是将代码更改为

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

I'd think that also fixes the problem with the overload: it seems the problem with not finding the correct overload is a follow-up problem of the nested type not being defined. 我认为这也可以解决重载问题:似乎找不到正确的重载的问题是未定义嵌套类型的后续问题。

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

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