There's no such thing as partial specialization of function templates. You
can either use a partially specialized helper class (make it a struct with a
static helper function), or an overloaded set of function templates (either
free functions or private member functions of the class you're working on).
The overload resolution that occurs between overloaded function templates
"looks like" partial specialization, even though it isn't. The major
difference between the two techniques is that overloading has to work on
arguments (you would have to introduce dummy T1 *, T2 * arguments or the
like, if your function is truly zero-arg), while partial specialization
doesn't.
Typically I would use a partially specialized helper class here.
STL
Post by Bogdan JokelThanks for the reply. I have no issues with compiling my real code. Of
course, the syntax for the template method that I typed into the post was
messed up . I don't even have a good excuse for it :)...
But my question still remains. How can I partially specialize the foo()
method? That is, I'd like to write method implementation for class C1 but
still have T2 parameter. Currently I have a templated method and
template <typename TR, typename TS> void ClassT<TR, TS>::foo()
{
[...]
}
// Specialized method
template <> bool ClassT<C1, C2>::foo()
{
[...]
}
This works fine. But I'm looking for something like the following (please
template <C1, typename TS> void ClassT<C1, TS>::foo()
Is this possible in C++?
Thanks.
Post by Bogdan JokelHi,
template <typename T1, typename T2> class ClassT
{
void foo();
}
template <typename T1, typename T2> void ClassT::foo<T1, T2>()
That's incorrect. 'foo' is not a template. 'ClassT' is a template. The
template<typename T1, typename T2> void ClassT<T1,T2>::foo()
Post by Bogdan Jokel{
[...]
}
template <> void ClassT::foo<C1, C2>()
{
[...]
}
Is there a way that I could have a partial specialization for the foo
method? For example, I'd like to have a specialized foo() for class C1
only (replacing typename T1).
Try the correct syntax, place the template arguments where they belong.
And try dropping the 'template<>' syntax, thus making your
void ClassT<C1,C2>::foo()
{
.. whatever
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask