我无法编译 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_t
和 unsigned
.这意味着,您的编译器认为 std::size_t
和 unsigned
是模板参数推导的不同类型(is_same_type::value == false
),但后来发现类型推导std::size_t
和 unsigned
属于同一类型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>
冲突编译器提示。
关于c++ - 在 RAD Studio 2010 中编译 yaml-cpp 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2386552/