我不能编译 yaml-cpp 在Rad Studio 2010中。我有错误 nodeutil.h

template <typename T, typename U>
struct is_same_type {
enum { value = false };
};

template <typename T>
struct is_same_type<T, T> {
enum { value = true };
};

template <typename T, bool check>
struct is_index_type_with_check {
enum { value = false };
};

template <> struct is_index_type_with_check<std::size_t, false> 
    { enum { value = true }; }; // line 24

#define MAKE_INDEX_TYPE(Type) \
template <> struct is_index_type_with_check<Type, is_same_type<Type, std::size_t>::value> { enum { value = true }; }

MAKE_INDEX_TYPE(int);
MAKE_INDEX_TYPE(unsigned); // line 30
MAKE_INDEX_TYPE(short);
MAKE_INDEX_TYPE(unsigned short);
MAKE_INDEX_TYPE(long);
MAKE_INDEX_TYPE(unsigned long);
#undef MAKE_INDEX_TYPE

编译器印刷:

[BCC32 Error] nodeutil.h(30): E2238 Multiple declaration for 'is_index_type_with_check<unsigned int,0>'

[BCC32 Error] nodeutil.h(24): E2344 Earlier declaration of 'is_index_type_with_check<unsigned int,0>'

我认为这一切都正确 - 在第24行中,我得到了

is_index_type_with_check<std::size_t, false>,

在第30行,我得到了

is_index_type_with_check<unsigned, true>.

两种不同的类型。

但是,如果我像下面更改24行,Rad Studio可以编译 yaml-cpp

template <> struct is_index_type_with_check<std::size_t, true> { enum { value = true }; }; // false -> true

为什么?!在第24行中我得到了

is_index_type_with_check<std::size_t, true>

在第30行

is_index_type_with_check<unsigned, true>

两个相同类型。但是所有在Rad Studio中的工作,也没有在MS VS 2008 Express中进行。

有帮助吗?

解决方案

使用CodeBlocks尝试代码,这些问题完全显示出副主席。这意味着,我的代码与

template <> struct is_index_type_with_check<std::size_t, false>

并且失败了

template <> struct is_index_type_with_check<std::size_t, true>

在第24行。

问题似乎是,哪些类型编译器认为是相同的,哪些是不同的。这个问题扩散在编译过程的不同阶段。再次查看您的编译器错误。模板参数 is_index_type_with_check 两者都一样 std::size_tunsigned. 。这意味着,您的编译器认为 std::size_tunsigned 是模板参数扣除的不同类型(is_same_type::value == false),但是后来发现的类型扣除 std::size_tunsigned 相同类型 unsigend int 并抱怨错误。

因此,总而言之,您没有正确读取编译器错误 - MAKE_INDEX_TYPE(unsigned); 创建一个 is_index_type_with_check<unsigned int, false>. 。这种类型与您的冲突 template <> struct is_index_type_with_check<std::size_t, false> 编译器抱怨。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top