471,581 Members | 2,364 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,581 software developers and data experts.

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 1603

"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 XIAOLAOHU | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.