2012-08-23 47 views
3

我使用XCode將相當大的C/C++項目移植到Mac。一些C++類導入stringvector。這會導致一些奇怪的錯誤報告重新定義幾個std函數。例如,編譯器在<type_traits>中報告了redefinition of 'std::__is_integral'包括<string>導致std-lib函數的'redefinition'錯誤

我沒有得到任何其他錯誤,我絕對不會覆蓋任何這些std函數。當我評論包括string時,錯誤也消失了。

什麼可能會導致此行爲?

回答

2

事實證明,在C++代碼的某個地方 - 我爲這個項目繼承的 - 有一個bool的重新定義。 bool被重新定義爲int。因此,在type_traits頭(以及其他一些std-lib頭文件)中存在一些泛型方法的重複方法定義,這些方法定義了一個bool和一個int泛型參數。

例如在type_traits有:

template <> struct __is_integral<bool> : public true_type {}; 

template <> struct __is_integral<int> : public true_type {}; 

由於bool被重新定義爲INT這兩種方法具有相同的簽名,我得到這個redefinition of...錯誤。

+0

請不要將C++稱爲「C/C++」。這是Simply Wrong(R)。 –

+0

你說得對。抱歉。該項目有C和C++代碼,但所描述的問題隻影響C++代碼。 (我編輯了答案) – codingFriend1