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 有问题,因为它 "shadows template 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_type
的 typedef
非常简单:使模板参数列表中使用的类型对 intrusive_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;
// ...
我认为这也解决了重载问题:找不到正确重载的问题似乎是未定义嵌套类型的后续问题。
我正在努力将大型 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 有问题,因为它 "shadows template 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_type
的 typedef
非常简单:使模板参数列表中使用的类型对 intrusive_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;
// ...
我认为这也解决了重载问题:找不到正确重载的问题似乎是未定义嵌套类型的后续问题。