Original Post
Heya, i've got a question about templates. Lately i played around with templates and tried something like: Which makes sense, because the orginal sqrt() function does only take, "long double", "double", "float". So far so good. Now the real question. *g* Is there are a way to detect, if the type T needs to be typcasted and if so, build the function with the required typecast ? Or does this only works with explicit specialization ? Please bear with me and the example, i'm not so into templates ;) Thanks in advance! Impz0r
namespace math {
template<typename T> inline T sqrt (T value) {
return (::sqrt (value));
}
}
int main (...) {
float foo = math::sqrt (4.0f); // does work
long bar = math::sqrt (4); // does not work, the compiler reports: Error 2 error C2668: 'sqrt' : ambiguous call to overloaded function
}