By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Need info on Template specialisation

P: n/a
I have a question regarding template specialisation.

Assume I have a generic template class

template <class S, class T>

class A{

void f() {

// Some code here

}

}

I want to specialise the function f() for say A<int, S>.

Do I need to specialise the entire class.

If else how do i specialise just this fn/?
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ganesh wrote:
I have a question regarding template specialisation.

Assume I have a generic template class

template <class S, class T>

class A{

void f() {

// Some code here

}

}

I want to specialise the function f() for say A<int, S>.
You mean for A<int,T>?

Do I need to specialise the entire class.
Yes, you do.
If else how do i specialise just this fn/?


You cannot. No partial specialisations of function templates are allowed.
A simple way would be to overload 'f' in the class.

V
Jul 23 '05 #2

P: n/a
??

"Ganesh" <ga****************@gmail.com> ???????/???????? ? ????????
?????????: news:72**************************@posting.google.c om...
I have a question regarding template specialisation.

Assume I have a generic template class

template <class S, class T>

class A{

void f() {

// Some code here

}

}

I want to specialise the function f() for say A<int, S>.

Do I need to specialise the entire class.
No,if you want to explicitly specialize the function:

template<>
void A<int,float>::f()
{
// blahblah
}

Still,there is no way to"partially specialize the function for the class.

If else how do i specialise just this fn/?


Just like Victor said, overload.Or make the function templated if the design
allows.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.