Hello again, i ran into some trouble with Visual C++ 2008 when i tried to use a template function. I only get this error when i try to use the function from main().
I used another template function succesfully earlier, but i can not figure out what is wrong with this one.
Any help is appreciated.:)
This is the error message i receive :P
error LNK2019: unresolved external symbol "void __cdecl split2<class std::back_insert_iterator<class std::list<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::back_insert_iterator<class std::list<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > >)" (??$split2@V?$back_insert_iterator@V?$list@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@std@@@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$back_insert_iterator@V?$list@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@1@@Z) referenced in function _main
This is part of my *.h file:
template <class Out>
void split2(const std::string&, Out);
And this is is part of my *.cpp file:
template <class Out>
void split2(const string& str, Out os) {
typedef string::const_iterator iter;
iter i = str.begin();
while (i != str.end()) {
// ignore leading blanks
i = find_if(i, str.end(), not_space);
// find end of next word
iter j = find_if(i, str.end(), space);
// copy the characters in [i, j)
if (i != str.end())
*os++ = string(i, j); // changed
i = j;
}
}
Edit: This is an example of how i want to use it in main():
string s;
while (getline(cin, s))
split2(s, ostream_iterator<string>(cout, "\n"));