#include <iostream>
#include <string>
template<int T, int U>
void foo(T a, U b)
{
std::cout << a+b << std::endl;
}
int main() {
foo(2,4);
return 0;
}
I get the following errors:
error: variable or field 'foo' declared void
error: expected ')' before 'a'
error: expected ')' before 'b'
In function 'int main()': error: 'foo' was not declared in this scope
typename
s, notint
s. – Sam Varshavchikint
s? Obviously, I could just create a standard function, but can it be done using templates? – asymmetryFanT
is not a type,foo
can't be function. Thus, it must be a variable, andvoid
is not a valid type for a variable. (Note thattemplate<int T> int variable(T);
is a valid declaration in C++14.) – molbdniloint
, you shouldn't use a template function. – molbdniloint
you just declare an ordinary function with two int parameters. That's it. That's what ordinary functions are for. This is not what templates are for. – Sam Varshavchik