"BekTek" <be****@gmail.com> wrote in message
I'm still confused about the template partial specialization which is used
in many libraries..
due to lack of introduction for beginner..
Consider this code -
#include <iostream>
using namespace std;
template<class T1, class T2>
struct A
{
void foo()
{
cout << "Primary template\n";
}
};
template<class T1>
struct A<T1, int>
{
void foo()
{
cout << "Partial specialization\n";
}
};
int main()
{
A<float, double> a1;
a1.foo(); // Calls primary template
A<float, int> a2;
a2.foo(); // Calls partial specialization
}
Analyze the code, whenever the second template parameter is an int the
partial specialization gets chosen.
Sharad