zoukankan      html  css  js  c++  java
  • [C++ Template]what is the type of instantiation of template function.

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

  • 相关阅读:
    Java——多线程常见面试题
    Java——线程定时器
    Java——多线程练习
    Java——线程池
    Java——线程间通信
    Java——线程死锁问题
    Java——线程同步
    Java多线程安全问题
    Java——多线程面试问题
    Java——多线程小例子
  • 原文地址:https://www.cnblogs.com/aoaoblogs/p/2099052.html
Copyright © 2011-2022 走看看