我正在使用 XCode 将一个相当大的 C/C++ 项目移植到 Mac。一些 C++ 类导入string或vector. 这会导致一些奇怪的错误报告重新定义几个 std 函数。例如编译器redefinition of 'std::__is_integral'在<type_traits>.
我没有收到任何其他错误,而且我绝对不会覆盖任何这些标准函数。当我评论string.
什么可能导致这种行为?
事实证明,在我为这个项目继承的 C++ 代码中的某个地方重新定义了bool. bool被重新定义为int。因此,在标头(和其他一些 std-lib 标头)中,存在具有 a和泛型参数type_traits的泛型方法的重复方法定义。boolint
例如在 type_traits 中有:
template <> struct __is_integral<bool> : public true_type {};
和
template <> struct __is_integral<int> : public true_type {};
正如bool被重新定义为 int 两种方法具有相同的签名,我得到了这个redefinition of...错误。