I have some trouble using a default argument of type float:
#include <wchar.h>
#include <iostream>
template<typename T>
void fun(T t = 1e-05);
template<typename T> inline
void fun(T t)
{
std::cout << t << std::endl;
}
int wmain(int argc, wchar_t* argv[])
{
fun<float>();
_getwch();
return 0;
}
It prints -1.36867e-033 instead of the equivalence of 1e-05. What is going on here?
I'm using VC++10.
EDIT1:
Thank you all for your replies. But casting the default argument doesn't work in the following case:
template<typename T>
void fun(T t = static_cast<T>(1e-05));
template<typename T> inline
void fun(T t)
{
std::wcout << t << std::endl;
}
int wmain(int argc, wchar_t* argv[])
{
fun<double>();
fun<float>();
_getwch();
return 0;
}
So this is definitely a bug and worth reporting?
EDIT2: