C++ – Link error: unresolved operator << for std::basic_ostream with CStringT

cmfc

I just reorganized some libraries of my Visual C++ (7.1) project and got trouble with the linker i cannot resolve.

The Project links MFC as well as Standard Windows Libraries, all MBCS

Somewhere, there is something like :

std::stringstream sstr;
sstr << m_MyCStringVar << std::endl;

(this line, as well as some others, needs << for basic_stream and CString)

Everything was fine until i merged 2 other libraries into 1 libraries (just moving the code/files from a to b without changing much)

Suddenly, all my exe's produce the linker error:

BasicFunctionsD.lib(CAccess.obj) : error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class ATL::CStringT > > const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "protected: void __thiscall CAccessor::CreateCategory(int,char const *,char const *)" (?CreateCategory@CAccessor@@IAEXHPBD0@Z)

(above code wasn't affected from the library merge, at least not directly)

As far as i can recognize, the << operator for basic ostream and CString is not found.

Maybe the lib containing MFC versions of basic_ostream is not found?

But i have no idea how to fix it or even where to start searching for the real problem.

Any hints would be nice

Best Answer

arg...

Simple reason: there is no std::ostream operator with CString... it was my own code and i just did not remember... :( During cleanup , the function went into a namespace and got lost

D'oh!

namesspace StupidcleanupIshouldNotHavedone { std::ostream & operator<<(std::ostream & s, const CString & str) { s << (LPCTSTR)str; return s; } }

Related Topic