Ray's playground

 

C++ templates chapter 4(Nontype template parameters)

  • Templates can have template parameters that are values rather than types.

  • You cannot use floating-point numbers, class-type objects, and objects with internal linkage (such as string literals) as arguments for nontype template parameters.

1 template <typename T, int VAL> 
2 T addValue (T const& x) 
3 
4     return x + VAL; 
5 

 

1 std::transform (source.begin(), source.end(),  
2                 dest.begin(),                                  
3                (int(*)(int const&)) addValue<int,5>);

 

stack4.hpp

 

stack4test.cpp

 

posted on 2009-09-22 12:27  Ray Z  阅读(254)  评论(0编辑  收藏  举报

导航