template <typename T> void function(T arg1,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max())
{
}
template <> void function<int>(int arg1, int min,int max)
{
}
int main(int argc,char* argv[])
{
function<int>(1);
}
it give syntax error C2689 and C2059 on function default argument line on ::
token.
but without specialization, it doing fine. and if I change default argument
and still doing specialization:
template <typename T> void function(T arg1,
T min = T(0),
T max = T(1))
{
}
template <> void function<int>(int arg1, int min,int max)
{
}
the problem gone too.
now if I use it like this: function<int>(1,2,3);
or function<float>(1.0f)
its fine, so it seems that if template function is specialized, we must rewrite the default argument when call it?
but on my second case, where i replace std::numeric_limits<T>::..
with T(..)
there no syntax error when calling function<int>(1)
, why is that?
(I'am using Visual Studio 2010 x64)
as original problem is because of bug, the question now changed to how to workaround it?