D
Dilip
I was reading the C++ templates (Josuttis et al) book and came across
an example that left me scratching my head.. there is a function
template:
template<typename T, int val>
T addvalue(T const& x)
{
return x + val;
}
that is used in transform like so:
std::transform(source.begin(), source.end(), dest.begin(),
addvalue<int, 5>);
the author goes on to say that because of some function template
overload issues we actually need to cast the last parameter like this:
(int(*)(int const&)) addvalue<int, 5>
can someone please enlighten me? why is the cast needed? i also don't
understand (embarassingly) what it means to say int(*)
an example that left me scratching my head.. there is a function
template:
template<typename T, int val>
T addvalue(T const& x)
{
return x + val;
}
that is used in transform like so:
std::transform(source.begin(), source.end(), dest.begin(),
addvalue<int, 5>);
the author goes on to say that because of some function template
overload issues we actually need to cast the last parameter like this:
(int(*)(int const&)) addvalue<int, 5>
can someone please enlighten me? why is the cast needed? i also don't
understand (embarassingly) what it means to say int(*)