我正在尝试编译我在网上找到的一些旧游戏SRC这里的代码
bool LoadFromINI(std::wstring const& strINIFileName = _T("./Local.ini"), char const* szDefaultLocale = "");
bool LoadFromINB(std::wstring const& strINBFileName, wchar_t const* szDefaultLocale = _T(""));
C:\...\...Code\Cel_Convert_Source\Cosmos\include\BM/LocalMgr.h(60): error C2440: 'default argument' : cannot convert from 'const char [1]' to 'const wchar_t *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\...\...Code\Cel_Convert_Source\Cosmos\include\BM/LocalMgr.h(60): error C2548: 'LOCAL_MGR::CLocal::LoadFromINB' : missing default parameter for parameter 2
1>C:\...\...Code\Cel_Convert_Source\Cosmos\include\BM/LocalMgr.h(59): error C2440: 'default argument' : cannot convert from 'const char [12]' to 'const std::wstring &'
1> Reason: cannot convert from 'const char [12]' to 'const std::wstring'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\...\...Code\Cel_Convert_Source\Cosmos\include\BM/LocalMgr.h(103): fatal error C1903: unable to recover from previous error(s); stopping compilation
还有一个错误: 代码:
_tcscpy_s(m_kDBName,30, (wchar_t const*)in_strDBName);
输出:
' errno_t strcpy_s(char *,rsize_t,const char *)' :无法转换参数3来自' const wchar_t *'到#char; char *' 1 GT;指向的类型是无关的;转换需要reinterpret_cast,C风格的转换或函数式转换
答案 0 :(得分:2)
将_T("blah")
更改为L"blah"
。
_T
是一个不执行任何操作或添加L
的宏。
或者,使用_T
和TCHAR
的
答案 1 :(得分:0)
仅当您的项目是使用定义的_T("str")
预处理程序符号进行编译时,L"str"
才会扩展为UNICODE
。在你的情况下,它似乎不是,所以_T()
什么都不做。将函数声明更改为
bool LoadFromINI(std::wstring const& strINIFileName = L"./Local.ini", wchar_t const* szDefaultLocale = "");
bool LoadFromINB(std::wstring const& strINBFileName, wchar_t const* szDefaultLocale = L"");
或者如果你真的,真的必须支持_T()
和TCHAR
的内容,请将其更改为
bool LoadFromINI(std::basic_string<TCHAR> const& strINIFileName = _T("./Local.ini"), TCHAR const* szDefaultLocale = "");
bool LoadFromINB(std::basic_string<TCHAR> const& strINBFileName, TCHAR const* szDefaultLocale = _T(""));
现在第一个参数将是std::string
或std::wstring
,具体取决于是否定义了UNICODE
。