Patrick Kutch wrote in news:400dfe10$1@nntp0.pdx.net:
[color=blue]
> Please take a look at the following code snippit:
> -------------------------------------------------------
> template<class TraitClass=int>
> class TestClass
> {
> public:
> void CallFunc()
> {[/color]
This is suspect, why wre you passing in the current template's
paramiter, members are already "specialized" on this paramiter.
[color=blue]
> SpecializedFunct_<TraitClass>();
> }
>
> private:
> template<class TraitClass >
> void SpecializedFunct_(void)
> {
> // called for non-specialized
> }
>
> template<>
> void SpecializedFunct_<int>(void)
> {
> // specialized for TraitClass=int
> }
>
> template<>
> void SpecializedFunct_<char>(void)
> {
> // specialized for TraitClass=char
> }
> };
> -------------------------------------------------------
>
> It works GREAT with Visual Studio .NET 2003. Complains to high-heaven
> with the gcc 3.2.2 compiler that came with Red Hat Linux 9.0.
>[/color]
I got it to compile with CBUilderX (has an EDG frontend) also.
[color=blue]
> I have done some digging and found a few blurbs in my google-mining
> that says something to the effect that specialization of member
> functions for a non-specialized class is not supported.
>
> So I have 2 questions:
>
> 1. Has the standard changed and MS is on the ball, or is it a MS
> compiler extension that allows this to work?
>[/color]
Nope, but its quite common for compilers to get this "cutting edge"
stuff wrong. Which is wrong though I don't know, though in my brief
scan of the standard I was unable to find anything excluding them.
Note that there is no way of defining these specialization's outside
the of the class template, so *if* legal they have to be "inline".
[color=blue]
> 2. Would greatly appreciate suggestions on how to get around this
> issue, I really really would like to have specialized member
> functions.
>[/color]
The usual workaround is an extra level of indirection:
template < typename T > class TestClass; // forward
template < typename T >
struct SpecializedMember_helper
{
template < typename U >
static void apply( TestClass< U > &that )
{
//non specilaized functionality
}
};
template < >
struct SpecializedMember_helper< int >
{
template < typename U >
static void apply( TestClass< U > &that )
{
//int specilaized functionality
}
};
template < typename Traits >
class TestClass
{
//...
template < typename T >
void SpecializedMember_()
{
SpecializedMember_helper< T >::apply( *this );
}
};
This also works for partial specialization's.
If T always equals U in your real code (as it did in your example)
then SpecializedMember_helper<T>::apply() doesn't need to be a
template.
HTH.
Rob.
--
http://www.victim-prime.dsl.pipex.com/