Advertisement
Guest User

templateFunctionTemplateArgument

a guest
Feb 22nd, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. bool something, something_else;
  4. template<class T>
  5. int sum(T a, T b)
  6. {
  7.     return a + b;
  8. }
  9.  
  10. template< template<typename> class Func >
  11. int function(int X, int Y, Func OP)
  12. {
  13.     if (something)
  14.         return OP<int>(X,Y);
  15.     else if(something_else)
  16.         return OP<double>(X,Y);
  17. }
  18.  
  19. int main()
  20. {
  21.     int n1 = 1, n2 = 2;
  22.     function(n1, n2, sum);
  23.     return 0;
  24. }
  25.  
  26. /*
  27. ERRORS:
  28.  
  29. testTemplate.cpp(11) : error C3205: argument list for template template parameter 'Func' is missing
  30. testTemplate.cpp(22) : error C2896: 'int function(int,int,Func)' : cannot use function template 'int sum(T,T)' as a function argument
  31.     testTemplate.cpp(5) : see declaration of 'sum'
  32. testTemplate.cpp(22) : error C2784: 'int function(int,int,Func)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
  33.     testTemplate.cpp(11) : see declaration of 'function'
  34. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement