类定义文件中的Win32程序编译器错误

问题描述

| 我正在尝试在Visual C ++中进行编译,只是将此配置文件加载器/解析器添加到了我的项目中。对于类CProfileData中定义的某些函数,至少会收到以下两个错误之一:
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,wstring& valueRet );
    UVSS_API bool GetvariableInt( const string& sectionName,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;

};
    

解决方法

包括
<string>
#include <string>
在写
string
的地方写write4ѭ。 在头文件中执行以下任一操作不是一个好主意:
using namespace std; //avoid doing this
using std::string;   //avoid doing this as well
    ,确保在包含此标题之前出现以下两行:
#include <string>
using std::string;