c++ - 链接错误 CString

标签 c++ mfc linker 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" (?_campaignFolderPath@CConfiguration@@0V?$CStringT@_WV?$StrTraitMFC@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@A)

我有一个定义为的类:

class CConfiguration
{
private:
    static CString _campaignFolderPath;

public:
    static void Read();

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

其Read方法定义为:

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

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

    _campaignFolderPath = temp;
}

关于错误原因的任何线索?我正在使用 Visual Studio 2008

最佳答案

您需要实例化该字符串,您现在只需将其声明为静态即可。添加:

CString CConfiguration::_campaignFolderPath;

在实现文件中。

关于c++ - 链接错误 CString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1510010/

相关文章:

visual-studio - 如何从 Visual Studio 获取确切的编译器命令行?

c# - 使用 CLR C++ 包装器从 C# 应用程序在 C++ 中加载 SDL 窗口不起作用

c++ - 避免多个 bool 值的优雅方法?

c++ - DirectShow - 无法创建新线程

c++ - C++ 应用程序的框架

c++ - 链接项目 C++ Cygwin

c++ - 音频关闭时线程很慢

C++ sdl : can i have an sdl-opengl window inside a menu and buttons i created with glade?

c++ - MFC:到底什么是 CSplitterWnd 插入符?

windows - 如何将 .asm 文件汇编并链接到 Win32 可执行文件?