2017-03-07 76 views
0

我創建了一個裝飾類的std :: string的是,包含在項目的時候,會導致數以千計的文件,如cmath.h,cstring.h,xstring發起構建錯誤的許多構建錯誤.h和我不知道爲什麼。爲了保持一致性,需要字符串操作的項目中的所有文件都使用此類而不是std :: string。串裝飾類導致

我試圖慢慢註釋掉裝飾類的零件要儘量使什麼是實際發生的感覺,但錯誤纔開始變得有意義,一旦整個班級被註釋掉。有太多的錯誤一一列出,但錯誤的小樣本包括:

Error C2733 'abs': second C linkage of overloaded function not allowed 
Error C2065 'allocator': undeclared identifier 
Error C2974 'std::basic_string': invalid template argument for '_Alloc' 
Error C2873 'strxfrm': symbol cannot be used in a using-declaration 
Error C2535 'void std::basic_string<_Elem,_Traits,_Alloc>::_Construct(_Iter,_Iter)': member function already defined or declared 

有成千上萬的跨越多個標準庫文件中的這些錯誤。這是字符串裝飾頭文件:

#pragma once 

#include <string> 
#include <vector> 

namespace Framework 
{ 
    class String 
    { 
    private: 
     std::string Data; 

    public: 
     String(); 
     String(const char*Init); 
     String(int Init); 

     friend String operator+(String &LHS, String &RHS); 
     friend String operator+(String &LHS, const char *RHS); 
     friend String operator+(String &LHS, const char RHS); 

     String& operator+=(String &RHS); 
     String& operator+=(const char *RHS); 
     String& operator+=(const char RHS); 

     friend bool operator==(String &LHS, String &RHS); 
     friend bool operator==(const String &LHS, const String &RHS); 
     friend bool operator==(String &LHS, const char *RHS); 
     friend bool operator==(const String &LHS, const char *RHS); 

     friend bool operator!=(String &LHS, String &RHS); 
     friend bool operator!=(const String &LHS, const String &RHS); 
     friend bool operator!=(String &LHS, const char *RHS); 

     String& operator=(const char * RHS); 

     char operator[](int Index); 

     size_t Length(); 
     size_t IndexOf(String SubString, size_t Offset = 0); 

     bool Contains(String SubString, size_t Offset = 0);   
     String SubString(size_t Start, size_t Count = 0);   
     std::vector<String> Split(char Delimeter, bool KeepEmpty = false); 

     const char *ToCharString(); 

     void Insert(int Position, String Text); 
     void RemoveAt(int Index); 

     int ToInt(); 
     double ToDouble();   
     bool ToBoolean(); 
     unsigned __int8 ToByte(); 
    };  
} 

是什麼使這更令人費解的是,這個門面在另一個項目中完美工作,它只是因爲它似乎沒有這個新項目。

+0

你張貼編譯什麼,我與Visual Studio,但顯然你已經發布是不是一個完整的例子所以誰知道什麼是在我們看不到的代碼。你能編譯其他東西嗎? –

+0

是的,這個項目很大且很複雜,有很多移動部件。我能夠編譯其他使用相同裝飾類的項目。但在這種情況下,它的一個項目使用它,它不會編譯。 – user1435899

+0

如果這段代碼在另一個項目中工作,那麼它看起來像這個代碼不是問題,其他的是。 –

回答

1

我不能完全確定是什麼原因導致這個問題,但它的分辨率是移動STRING.H和String.cpp文件到子文件夾中的項目,而不是讓它坐在項目的根目錄。一旦我完成了這一切,並將所有東西都還原爲使用Framework :: String,該項目就可以正常工作了。

一個線索,爲什麼這個工作可能是因爲,如果我右鍵單擊一個#include "String.h"行時,String.h和String.cpp仍然在根目錄並選擇打開文檔,它打開標準庫字符串.h文件而不是我的String.h文件。