1

I am a bit confused because I've read that partial specialization of the function template in C ++ is not possible, but it works for me (gcc 5.3.0).

My example:

#include <iostream>
using namespace std;

template <typename T1, typename T2>
void fun(T1 a, T2 b){
    cout << "template\n";
}

template <typename T1>
void fun(T1 a, int b){
    cout << "Function partialy specialized\n";
}

int main(){

    fun("ab", "cd"); //template
    fun(2,2);        //Function partialy specialized
    fun("xx", 2);    // Function partialy specialized
}

How is it really correct?

maxopt
  • 11
  • 1
  • 3
    This isn't a partial specialization. It is an overload – NathanOliver May 08 '18 at 19:08
  • Why is an overload? – maxopt May 08 '18 at 19:31
  • Function overloading is the process of writing multiple functions that have the same name bu different parameters. i.e. `int foo(int);` and `int foo(double)`. Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – NathanOliver May 08 '18 at 19:46
  • Yes, I know this, but I can't understand why my example is function overloading, not partial specialization. – maxopt May 08 '18 at 20:39
  • Could anyone provide me example with FUNCTION partial specialization according to my example? – maxopt May 08 '18 at 20:39
  • Because there is no partial specialization for function templates. So, instead of making a specialization you made an overload – NathanOliver May 08 '18 at 20:40

0 Answers0