I am getting an "unresolved external symbol" error in Visual Studio.
LNK2019 unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char>> & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class GenericStack<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > const &)" (??6@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV01@AEBV?$GenericStack@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@Z) referenced in function main in2post C:\*path*\in2post.obj
LNK2019 unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class GenericStack<double> const &)" (??6@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV01@AEBV?$GenericStack@N@@@Z) referenced in function main in2post C:\*path*\in2post.obj
I've spent many hours now troubleshooting this error, with no success. I've looked at many of the other posts on here that deal with this same error.
I think this is the problem "symbol":
friend ostream& operator<<(ostream& os, const GenericStack<T>& a);
This sits in my header file. The definition for the overload is in another .cpp file and looks like this:
template <typename T>
ostream& operator<<(ostream& os, const GenericStack<T>& a)
{
for (int i = a.size() - 1; i >= 0; --i)
a.print(os, a.top());
return os;
}
My main function is in a separate .cpp file that has #includes statements for both the header and the definitions. At this point I'm completely unsure what to do to resolve this. Any help is greatly appreciated.