Reputation: 4461
I've created this template, and put it at the very top of my .cpp above main() but I am still getting the following
error: C3861: 'ConvertNumbertoString': identifier not found.
Here is the template:
template<class T>
string ConvertNumberstoString(T number)
{
string outPut;
stringstream convert;
convert << number;
outPut = convert.str();
return outPut;
}
I know this is probably a stupid function to most of you guys, but it's what I need at the moment.
I can't figure out how to get rid of this error so that I can use it in my program.
Any thoughts?
Upvotes: 1
Views: 1761
Reputation: 17567
You want to return a string from the function template:
// In your cpp:
template<class T>
string ConvertNumberstoString(const T &number)
{
stringstream convert;
convert << number;
return convert.str();
}
int main()
{
string s = ConvertNumberstoString(42);
}
Upvotes: 3