469,117 Members | 1,321 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,117 developers. It's quick & easy.

Could anyone tell me about template partial specialization..?

I'm still confused about the template partial specialization which is used
in many libraries..
due to lack of introduction for beginner..

Could you tell me about that in short?
Thanks in advance..
Jul 22 '05 #1
1 1541

"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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Paul MG | last post: by
8 posts views Thread by Agent Mulder | last post: by
13 posts views Thread by Imre | last post: by
6 posts views Thread by Andre Kempe | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.