Explicit specialization of template class member function?

It doesn't work that way. You would need to say the following, but it is not correct template template void X::get_as() { } Explicitly specialized members need their surrounding class templates to be explicitly specialized as well. So you need to say the following, which would only specialize the member for XI prefer overloads template class X { template struct type { }; public: template void get_as() { get_as(type()); } private: template void get_as(type) { } void get_as(type) { } }.

It doesn't work that way. You would need to say the following, but it is not correct template template void X::get_as() { } Explicitly specialized members need their surrounding class templates to be explicitly specialized as well. So you need to say the following, which would only specialize the member for X.

Template template void X::get_as() { } If you want to keep the surrounding template unspecialized, you have several choices. I prefer overloads template class X { template struct type { }; public: template void get_as() { get_as(type()); } private: template void get_as(type) { } void get_as(type) { } }.

I guess it's not as elegant... – Nim Apr 1 at 12:08 Looks like this is really not possible to do.Thanks. – ledokol Apr 1 at 12:09 @Nim right, I think the pointer cast thing is ugly, and wouldn't work for types you can't form pointers to (references). Also, having a function parameter be a pointer to an array type without a size is illegal in C++.

Having it in a type wrapper makes it work for all types. – Johannes Schaub - litb Apr 1 at 12:09 oops, forgot about references... this approach is definitely more elegant.. – Nim Apr 1 at 12:10.

First of all: you don't have get_as specialization declared in your class template to be defined later in a code. So first you need to do this: template class X { public: template void get_as(); template void get_as(); }; Then define specialization: template template void X::get_as() { .... } But I would define it like this: template class X { public: template void get_as() { // default implementation } template void get_as() { // specialized implementation } }; SORRY THE ABOVE DOESN'T WORK! EDIT: It turns out that function template specializations are not allowed in non-namespace scope, i.e.In classes, class templates, etc. So you can make is as namespace-scope function template: template class X { public: } template void get_as( X& obj ) { // default implementation } template void get_as( X& obj ) { // specialized implementation }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions