Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- bool something, something_else;
- template<class T>
- int sum(T a, T b)
- {
- return a + b;
- }
- template< template<typename> class Func >
- int function(int X, int Y, Func OP)
- {
- if (something)
- return OP<int>(X,Y);
- else if(something_else)
- return OP<double>(X,Y);
- }
- int main()
- {
- int n1 = 1, n2 = 2;
- function(n1, n2, sum);
- return 0;
- }
- /*
- ERRORS:
- testTemplate.cpp(11) : error C3205: argument list for template template parameter 'Func' is missing
- testTemplate.cpp(22) : error C2896: 'int function(int,int,Func)' : cannot use function template 'int sum(T,T)' as a function argument
- testTemplate.cpp(5) : see declaration of 'sum'
- testTemplate.cpp(22) : error C2784: 'int function(int,int,Func)' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
- testTemplate.cpp(11) : see declaration of 'function'
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement