【发布时间】:2015-03-24 22:17:31
【问题描述】:
我正在将一个大型 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 存在问题,因为它“遮蔽了模板参数‘class base_type’”。显然它是有目的的,而且微软的编译器一定是允许的。
我对下面的 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++ 的,因为它不是我的主要语言,但到目前为止我通过尝试这个移植学到了很多东西,并将继续学到很多东西。我现在有点卡在这些错误上,希望有人能提供帮助。
谢谢。
【问题讨论】:
标签: c++ linux templates gcc typedef