Can someone please explain to me why the following won't compile?, and hopefully the obvious thing that I have missed...
functions.hpp:
template<typename T> string vector_tostr(std::vector<T> v);
functions.cpp:
template<typename T> string vector_tostr(std::vector<T> v){
std::stringstream ss;
std::string thestring = "";
if(v.size() > 0){
ss << "[";
for(size_t i = 0; i < v.size(); i++){
if(i != 0)
ss << " ";
ss << v[i];
}
ss << "]";
thestring = ss.str();
}
return thestring;
}
main.cpp
#include "functions.hpp"
int main(int argc, char *argv[]){
vector<int> thevector;
thevector.push_back(1);
thevector.push_back(2);
string result = vector_tostr(thevector);
//I have also tried vector_tostr<int>(thevector)
}
The cryptic error I am getting as follows:
Undefined symbols for architecture x86_64: "std::basic_string, std::allocator > vector_tostr(std::vector >)", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status make: * [main] Error 1