Function templates < explicit specializations < regular functions

Hi, I'm a newbie and I'm just learning the language.

The thing is, today I was just reading for the first time about function templates (implicit instantiations), and explicit specializations. The thing is, if explicit specializations override function templates, and both are overriden by regular functions... why would you use an explicit specialization to begin with? Wouldn't it be easier (without having to deal with syntax complications) to just use a regular function to override any template for type int for example?


Or has this extra-level any use?
Last edited on
If you create a regular function you can still use the template version by specifying the template argument.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

template <class T>
void foo(T)
{
	std::cout << "1\n";
}

void foo(int)
{
	std::cout << "2\n";
}

int main()
{
	foo(0);
	foo<int>(0);
}
2
1
Pretty interesting.

Thank you very much!
Topic archived. No new replies allowed.