the typename is unused in the specialization so there is no need of declaring it, in the same way when you don't use an argument of a function, you can avoid declaring it.. int f(int) { return 5; }
I got it thanks!
however its not an specialization right? its a function overload
Just learn from example; I won’t explain. — #include <iostream> using namespace std; template <typename T> T add1(T num1, T num2) { return (num1 + num2); } template <typename T, typename> T add2(T num1, T num2) { return (num1 + num2); } template <typename, typename> void print() { cout << "funny world" << endl; } int main() { int result1; double result2,result3; result1 = add1<int>(2, 3),(5.3,6.2); cout << "2 + 3 = " << result1 << endl; result2 = add2<int,double>(2,3),(2.1,3.1),(2.2,3.2),(2.3,3.3); cout << "2 + 3 = " << result2 << endl; print<int,char>(); result2 = add1<double>(2.2, 3.3); cout << "2.2 + 3.3 = " << result2 << endl; return 0; }
Modified again for simplicity..
oof, this screams use concepts
Обсуждают сегодня