There are many online documents explaining how to write template methods, but not many examples of calling them, how to use them in code.
I have a template method like this:
VectorConvertor.h
template <class T> static void AppendToVector(std::vector<T> & VectorToBeAppended, std::vector<T> & VectorToAppend);
VectorConvertor.cpp
template <class T> void VectorConvertor::AppendToVector(std::vector<T> & VectorToBeAppended, std::vector<T> & VectorToAppend) { for (std::vector::size_type i=0; i<VectorToAppend.size(); i++) { VectorToBeAppended.push_back(VectorToAppend.at(i)); } }
Attempted use in code:
std::vector<uint8_t> InputData, OutputData;
I compile this code without errors. But when I try to use this method, I get the following errors:
error LNK1120: 1 unresolved external
and
error LNK2019: unresolved external symbol "public: static void __cdecl VectorConvertor :: AppendToVector (class std :: vector> &, class std :: vector> &)" (? $ AppendToVector @E @VectorConvertor @@ SAXAEAV? $ vector @EV ? $ allocator @E @std @@@ std @@ 0 @Z) link in the function "public: staticclass std :: vector> __cdecl Utf8 :: WStringToUtf8 (class std :: basic_string, class std :: allocator>)" ( ? WStringToUtf8 @ Utf8 @@ SA? AV? $ Vector @EV? $ Allocator @E @std @@@ std @@ V? $ Basic_string @_WU? $ Char_traits @_W @std @@ V? $ Allocator @_W @ 2 @@ 3 @@ Z)
When I do not use this method in my code, I do not receive any error messages. What am I doing wrong when I call? Did I miss something?
I am using Visual Studio 2010 Express Edition.
c ++ function methods templates
hkBattousai
source share