It depends on the type T, as indicated in Space_C0wb0y.
Check the following code
#include <sstream>
#include <iostream>
template<typename T>
static std::string ToString(const T& t){
std::stringstream temp;
temp << t;
return temp.str();
}
struct empty{};
struct non_empty{
std::string str;
non_empty(std::string obj):str (obj){}
friend std::ostream& operator << (std::ostream& out, const non_empty &x);
};
std::ostream& operator << (std::ostream& out, const non_empty &x){
out << x.str;
return out;
}
int main(){
std::string s = ToString<double>(12.3); // this will work fine
/*********************************************************************************
* std::string k = ToString(empty()); // no match for 'operator<<' in 'temp << t'*
*********************************************************************************/
std::string t = ToString(non_empty("123")); // this works too
}
The call ToString(empty());gives the same error as yours, but ToString(non_empty("123")); fine . What does it mean?
source
share