【发布时间】:2010-03-05 12:13:38
【问题描述】:
我无法在 RAD Studio 2010 中编译 yaml-cpp。我在 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 中运行。
【问题讨论】:
-
你想在问题的最后一个块中写
std::size_t, true? -
我写这个。但我不明白两件事 - 为什么第一选择是错误的,为什么第二选择有效。我认为这与 SFINAE 相关,但在我的系统中
std::size_t等于unsigned int。
标签: c++ templates yaml c++builder yaml-cpp