The book <<C++ templates>> said:
however, in VS2008 and gcc 4.3, the compilers can deduce the type of parameter. The followed code has no compile error.
#include
<vector>
#include
<algorithm>
using
namespace
std;
template
<
typename
T,
int
VAL>
T addValue (T
const
& x) {
return
x + VAL;
}
int
main(
int
argc,
char
* argv[])
{
vector<
int
> source;
vector<
int
> dest;
int
(*funP)(
int
const
&);
funP = addValue<
int
,5>;
std::transform (source.begin(), source.end(),
// start and end of source
dest.begin(),
// start of destination
addValue<
int
,5>);
// operation
std::transform (source.begin(), source.end(),
// start and end of source
dest.begin(),
// start of destination
funP);
return
0;
}