Windows到Linux的端口c++错误

时间:2021-07-21 04:47:39

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’". Obviously there was some purpose for it and the Microsoft compiler must have allowed it.

GCC有一些问题,因为它是“阴影模板parm ' class base_type '”。显然,它是有目的的,微软的编译器一定是允许的。

I also have issues with the TEMPLATE_SPECIALIZATION stuff below giving errors like

我也有一些关于template_特殊化的问题

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. I'm a bit stuck on these errors at the moment and hope someone might be able to help.

我不是最精通c++,因为它不是我的主要语言,但到目前为止,我学到了很多通过尝试这个端口,将继续学到很多。我有点困在这些错误,希望有人可以帮助。

Thanks.

谢谢。

1 个解决方案

#1


3  

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. The trivial fix is to change the code to become

base_type的类型定义非常简单:要使模板参数列表中使用的类型对入侵者sive_ptr的用户可用(虽然,由于类型实际上是“private”,所以没有多大意义),该类型在模板定义中定义。简单的解决方法是更改代码。

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.

我认为这也解决了重载的问题:似乎没有找到正确的重载是嵌套类型没有定义的后续问题。

#1


3  

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. The trivial fix is to change the code to become

base_type的类型定义非常简单:要使模板参数列表中使用的类型对入侵者sive_ptr的用户可用(虽然,由于类型实际上是“private”,所以没有多大意义),该类型在模板定义中定义。简单的解决方法是更改代码。

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.

我认为这也解决了重载的问题:似乎没有找到正确的重载是嵌套类型没有定义的后续问题。