[C++ Template]what is the type of instantiation of template

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

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;
}

原文链接: https://www.cnblogs.com/aoaoblogs/archive/2011/07/06/2099052.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    [C++ Template]what is the type of instantiation of template

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/28195

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午5:44
下一篇 2023年2月8日 上午5:44

相关推荐