inline函数编译报错的奇怪问题!
我写了两个内联函数,声明放到了一个头文件里,实现放到了源文件里,编译通过,链接失败,提示说找不到对应的函数obj,提示如下:
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
hzSrc.obj : error LNK2019: unresolved external symbol "class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl GetWStr(wchar_t *)" (?GetWStr@@YA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PA_W@Z) referenced in function _wmain
hzSrc.obj : error LNK2019: unresolved external symbol "wchar_t * __cdecl CharToWideChar(char *)" (?CharToWideChar@@YAPA_WPAD@Z) referenced in function _wmain;
我的两个内联函数如下:
inline wstring GetWStr(wchar_t * pWch);
inline wchar_t* CharToWideChar(char* str);
我内联函数的定义如下:
inline string WideCharToString(CString str)
{
wchar_t *pw = str.GetBuffer() ;
int nLength = WideCharToMultiByte(CP_ACP, 0, pw, -1, NULL,0,NULL,NULL);
char *ch = new char[nLength];
WideCharToMultiByte(CP_ACP, 0, pw, -1, ch, nLength, NULL, NULL);
str.ReleaseBuffer();
string sch = ch;
delete [] ch;
return sch;
}
inline wstring GetWStr(wchar_t * pWch)
{
wstring wstr = pWch;
return wstr;
}
然后在main中的调用如下:
char * pch = "测试测试nnd";
wchar_t *pw1 = CharToWideChar(pch);
wstring sss = GetWStr(pw1);
编译就抛这个错,实在不明白啊!