The book <<C++ templates>> said:
[C++ Template]what is the type of instantiation of template function.

however, in VS2008 and gcc 4.3, the compilers can deduce the type of parameter. The followed code has no compile error.
look here(http://ideone.com/yTpaJ ) for gcc result.
#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;
}

相关文章:

  • 2022-02-17
  • 2021-11-12
  • 2021-07-27
  • 2021-07-01
  • 2021-12-14
  • 2021-09-15
  • 2021-12-28
  • 2022-02-21
猜你喜欢
  • 2021-12-22
  • 2021-10-10
  • 2022-12-23
  • 2022-03-08
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案