Original Post
I made up a quick function that would attempt to use stringstream to convert any data type to a string. It all went fine and dandy, but when I attempted to split it into a .h and .cpp file, it resulted in linker crashes. ... The source has been fixed. Results in:
///////////////////////////////////
// main.cpp
#include <iostream>
#include <string>
#include "encoding.h"
using namespace std;
int main(){
string a = ToString(4);
cout << a << endl;
a = ToString(543.514);
cout << a << endl;
cin.get();
return 0;
}
///////////////////////////////////
// encoding.h
#if !defined(_ENCODING_H_)
#define _ENCODING_H_
#include <string>
#include <sstream>
template <class T>
std::string ToString(T data){
std::stringstream temp;
temp << data;
return temp.str();
}
#endif
[Linker error] undefined reference to `std::string ToString<int>(int)' Anyone see what's wrong with it? (...Fixed) [Edited by - Rob Loach on February 21, 2005 4:24:37 PM]