Is there a partial specialization for template class method?
template <class A, class B>
class C
{
void foo();
}
it doesn't work to specialize it like this:
template <class A> void C<A, CObject>::foo() {};
Any help?
Is there a partial specialization for template class method?
template <class A, class B>
class C
{
void foo();
}
it doesn't work to specialize it like this:
template <class A> void C<A, CObject>::foo() {};
Any help?
If you are already have specialized class you could give different implementation of
foo
in specialized class:To specialize member function in Visual C++ 2008 you could make it template too:
The solution above seems to will be available only in future C++ Standard (according to draft n2914 14.6.5.3/2).
If I remember correctly, you cannot make partial template specialization for functions. Not sure whether it is included in C++0X
Update: (Awaiting confirmation)
As noted in the comments, partial template specialization of functions is possible in C++0X.I think there is a misunderstanding there.
There are two kinds of templates:
In your example, you have a template class, which of course contains some methods. In this case, you will have to specialize the class.
The problem in your example is relatively simple: you define the method foo for the specialization C but this specialization has never been declared beforehand.
The problem here is that you have to fully specialize your C class (and thus copying a lot of data). There are a number of workarounds.
Which in code gives:
Hope it clarifies, and helps!
No, there is no partial function template specialization in C++0x to be added.
As correctly mentioned above, with regards to function templates basically 2 things were done:
So as before, workarounds should be used to "emulate" partial function templates specialization.
Since the class is the template, you need to specialize that: