2009-10-02 26 views
3

我得到使用CString的錯誤鏈接錯誤是:鏈接出錯的CString

error LNK2001: unresolved external symbol "private: static class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > CConfiguration::_campaignFolderPath" ([email protected]@@[email protected][email protected][email protected][email protected]@@@@@[email protected]@A) 

我必須爲它定義一個類:

class CConfiguration 
{ 
private: 
    static CString _campaignFolderPath; 

public: 
    static void Read(); 

private: 
    CConfiguration(void); 
    ~CConfiguration(void); 
}; 

它的讀法的定義是:

void CConfiguration::Read() 
{ 
    CConfigFile configReader(_T("Config.ini")); 
    TCHAR temp[1024]; 

    configReader.GetStringValue(_T("Campaigns"), _T("CampaignsFolderPath"), temp); 

    _campaignFolderPath = temp; 
} 

什麼是導致錯誤的線索?我正在使用Visual Studio 2008

回答

7

您需要實例化字符串,您現在只是聲明它爲靜態。 Add:

CString CConfiguration::_campaignFolderPath; 

在執行文件中。

+0

錯誤C2039:'CString':不是'CConfiguration'的成員 – akif 2009-10-02 14:56:41

+0

CString CConfiguration :: _ campaignFolderPath;謝謝 – akif 2009-10-02 14:57:19

+0

請編輯您的答案,我相信它是一個錯字 – akif 2009-10-02 14:57:55

3

您是否有像下面某處的實現行?

CString CConfiguration :: _ campaignFolderPath;