2011-05-26 81 views
0

我想在Visual C++中編譯,並將這個配置文件加載器/解析器添加到我的項目中。對於類CProfileData定義了一些曾經函數接收兩個錯誤中的至少一個:類定義文件中的Win32程序編譯器錯誤

missing type specifier - int assumed. 
syntax error : missing ',' before '&' 

當顯然這應該只是一個參考的字符串

#ifdef UVSS_EXPORTS 
#define UVSS_API __declspec(dllexport) 
#else 
#define UVSS_API __declspec(dllimport) 
#endif 


class CProfileData 
{ 

public: 
    UVSS_API CProfileData(){}; 
    UVSS_API CProfileData(const string& profileFile); 
    UVSS_API ~CProfileData(void); 

    UVSS_API bool GetVariable(const string& sectionName, const string& variableName, string& valueRet); 
    UVSS_API bool GetSection(const string& sectionName, SECTION_MAP **pMapRet); 
    UVSS_API bool GetVariableW(const string& sectionName, const string& variableName, wstring& valueRet); 
    UVSS_API bool GetVariableInt(const string& sectionName, const string& variableName, int *pIntRet); 

private: 
    void ToLower(string& str); 
    void TrimWhitespace(string& str); 
    bool IsComment(const string& str); 
    bool IsSection(const string& str, string& secName); 
    bool IsVariable(const string& str, string& name, string& value); 

    PROFILE_MAP   m_mapProfile; 

}; 
+2

你試過' #include '?然後你需要將thos字符串變成'std :: string'。 – 2011-05-26 13:51:10

回答

6

包括<string>

#include <string> 

並寫std::string無論你寫了string

它不是一個好主意,做一個文件下列之一:

using namespace std; //avoid doing this 
using std::string; //avoid doing this as well 
+1

+1:擊敗我9秒。 – 2011-05-26 13:53:11

+0

感謝您的幫助! – jscott 2011-05-26 14:19:47

3

確保這兩個線,包括這個頭文件之前出現:

#include <string> 
using std::string; 
+0

-1這是非常糟糕的建議。包含應該*在*這個標題中,而不是在包含它的文件中。在頭文件中,除非項目範圍的約定另有說明,否則最好避免使用'',並在每次使用時完全指定'std :: string'。 – 2011-05-26 14:33:21

+0

我同意@詹姆斯的建議。但是,我從@ Joe的請求推斷出這個頭文件是外部依賴項,他無法對其進行編輯。 – 2011-05-26 15:02:52