V
Vijai Kalyan
I wrote the following function as a curiosity:
template<typename SourceType,
typename DestinationType>
DestinationType NumericCast(const SourceType& value) {
std::wstringstream strbuf;
strbuf << value << std::endl ;
strbuf.flush();
DestinationType convalue;
strbuf >> convalue;
return convalue;
}
This works fine for all numeric types such as int to long, long to
float etc.
However, I tried the following:
NumericCast<char, int>('c');
This failed to return the correct value. When I stepped through the
function, the value of "convalue" remained the same throughout. But
this happened only when SourceType was char. A
I tried stepping into the operator code, but my debugger just stepped
over so I am not sure what's going on inside.
Anyone have any ideas on anything I am doing that is obviously wrong,
but which I am missing?
thanks,
-vijai.
template<typename SourceType,
typename DestinationType>
DestinationType NumericCast(const SourceType& value) {
std::wstringstream strbuf;
strbuf << value << std::endl ;
strbuf.flush();
DestinationType convalue;
strbuf >> convalue;
return convalue;
}
This works fine for all numeric types such as int to long, long to
float etc.
However, I tried the following:
NumericCast<char, int>('c');
This failed to return the correct value. When I stepped through the
function, the value of "convalue" remained the same throughout. But
this happened only when SourceType was char. A
I tried stepping into the operator code, but my debugger just stepped
over so I am not sure what's going on inside.
Anyone have any ideas on anything I am doing that is obviously wrong,
but which I am missing?
thanks,
-vijai.