I am using Visual Studio 2008. I am getting a linker error when creating a project that contains a statically linked library only when using MFC CString (vs std :: wstring).
So this works:
//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(); }
But this
//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(); }
gives the linker error:
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)
In both projects, the calling convention is indicated as __cdecl in the project file. So why __thiscall arises, and how can I fix it? I have to use __cdecl because I reference external libraries that use __cdecl .
Additional project settings:
Both projects have the following settings:
- "Using MFC": use MFC in a shared DLL
- "Using ATL": not using ATL
- Character Set: Use the Unicode character set.
source share