我正在使用 Visual Studio 2008。仅在使用 MFC CString(与 std::wstring 相比)构建包含静态链接库的项目时,我收到链接器错误。
所以这有效:
//header
class FileProcessor
{
public:
class iterator;
friend class iterator;
//...
class iterator : public std::iterator<std::input_iterator_tag, std::vector<std::vector<std::wstring>>>
{
public:
//...
std::vector<std::vector<std::wstring>> operator*() const;
}
}
//cpp
std::vector<std::vector<std::wstring>> FileProcessor::iterator::operator*() const
{
return _outerRef->_pimpl->_saxHandler->GetCurrentTable();
}
但是这个
//header
#include <afx.h>
class FileProcessor
{
public:
class iterator;
friend class iterator;
//...
class iterator : public std::iterator<std::input_iterator_tag, std::vector<std::vector<CString>>>
{
public:
//...
std::vector<std::vector<CString>> operator*() const;
}
}
//cpp
std::vector<std::vector<CString>> FileProcessor::iterator::operator*() const
{
return _outerRef->_pimpl->_saxHandler->GetCurrentTable();
}
给出链接器错误:
FileProcessingTests.obj : error LNK2019: unresolved external symbol "public: class
std::vector<class std::vector<class std::basic_string<wchar_t,struct
std::char_traits<wchar_t>,class std::allocator<wchar_t> >,class std::allocator<class
std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class
std::allocator<wchar_t> > > >,class std::allocator<class std::vector<class
std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class
std::allocator<wchar_t> >,class std::allocator<class std::basic_string<wchar_t,struct
std::char_traits<wchar_t>,class std::allocator<wchar_t> > > > > > __thiscall
FileProcessing::FileProcessor::iterator::operator*(void)const "
(??Diterator@FileProcessor@FileProcessing@@QBE?AV?$vector@V?$vector@V?$basic_string@_WU?
$char_traits@_W@std@@V?$allocator@_W@2@@std@@V?$allocator@V?$basic_string@_WU?$char_traits
@_W@std@@V?$allocator@_W@2@@std@@@2@@std@@V?$allocator@V?$vector@V?$basic_string@_WU?$
char_traits@_W@std@@V?$allocator@_W@2@@std@@V?$allocator@V?$basic_string@_WU?$char_traits
@_W@std@@V?$allocator@_W@2@@std@@@2@@std@@@2@@std@@XZ) referenced in function "void
__cdecl TestUnicodeSingleTable(void)" (?TestUnicodeSingleTable@@YAXXZ)
在这两个项目中,调用约定都__cdecl
在项目文件中指定。那么为什么__thiscall
甚至会出现,我该如何解决呢?我必须使用__cdecl
,因为我正在引用使用__cdecl
.
附加项目设置:
这两个项目都有以下配置设置:
- “使用 MFC”:在共享 DLL 中使用 MFC
- “使用 ATL”:不使用 ATL
- “字符集”:使用 Unicode 字符集