c++ - Boost 进程间在 gcc 4.1.2 上失败

标签 c++ templates gcc

我正在尝试使用 Boost::Interprocess,但在尝试使用 gcc 4.1.2 进行编译时出现了一些编译器错误。我缩小了代码范围并设法在没有提升的情况下重现了问题。代码是:

#include <iostream>
static const std::size_t offset_type_alignment = 0;

template<class T, class U>
struct pointer_to_other;

template<class T, class U, template<class> class Sp>
struct pointer_to_other< Sp<T>, U >
/*144*/{
   typedef Sp<U> type;
};

template <class PointedType, class DifferenceType, class OffsetType, std::size_t OffsetAlignment>
class offset_ptr
{
};
template <class T, class DifferenceType = std::ptrdiff_t, class OffsetType = std::size_t, std::size_t Alignment = offset_type_alignment>
class offset_ptr;


template<class T, class T2, class T3, std::size_t A, class U>
/*158*/struct pointer_to_other<offset_ptr<T, T2, T3, A>, U >
{
   typedef offset_ptr<U, T2, T3, A> type;
};


template<class VoidPointer>
class message_queue_t
{
   typedef VoidPointer                                                 void_pointer;
/*167*/   typedef typename pointer_to_other<void_pointer, char>::type         char_ptr;
};

int main()
{
/*177*/       message_queue_t< offset_ptr<void, std::ptrdiff_t, std::size_t, offset_type_alignment> > test;
}

我得到的错误:

.cc: In instantiation of message_queue_t >

.cc:177: instantiated from here

.cc:167: error: ambiguous class template instantiation for struct pointer_to_other, char>

.cc:144: error: candidates are: struct pointer_to_other, U>

.cc:158: error: struct pointer_to_other, U>

.cc:167: error: invalid use of undefined type âstruct pointer_to_other, char>

.cc:140: error: declaration of âstruct pointer_to_other, char>â

在 MSVS 中,这可以正常编译。 Ideone也可以正常编译,但它使用 gcc 4.3.4

重要

  • 改变编译器是不可能的
  • 我知道 Boost::Interprocess 没有用这个版本的 gcc 测试过

我正在寻找一种解决方法。有什么想法吗?

PS - 模板是提升的一部分,但减少了,所以我不能真正改变它们。有什么办法可以改变:

 message_queue_t< offset_ptr<void, std::ptrdiff_t, std::size_t, offset_type_alignment> > test;

为了让它发挥作用?

最佳答案

这是一个编译器限制。它根本不受支持。

关于c++ - Boost 进程间在 gcc 4.1.2 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10225760/

相关文章:

c++ - n维 vector

c++ - 如何更改模板实例化顺序?

c++ - 将结构中的结构指针成员存储到 vector 中的简便方法

模板的 C++ 链接错误,仅使用头文件,为什么?

c++ - 使用 malloc : why did it happen? 的内存分配导致堆损坏

c++ - 具有不同模板的派生类对象的 vector

c - fatal error : omp. h:没有这样的文件或目录使用 arm-unknown-linux-uclibcgnueabi (crosstool-ng)

linux - 在没有 liblttng-ust-cyg-profile 的情况下获取 lttng 回溯

c++ - 我可以在下面的代码中使用任何编译器标志来报告有关 UB 的警告吗?

c++ - 像这样调整 vector 大小时如何避免段错误