Re: Template Specialization, subclassing and overriding
From: John Carson (donaldquixote_at_datafast.net.au)
Date: 02/07/04
- Next message: zero: "Overriding Methods"
- Previous message: David Rasmussen: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- In reply to: Rob Williscroft: "Re: Template Specialization, subclassing and overriding"
- Next in thread: Rob Williscroft: "Re: Template Specialization, subclassing and overriding"
- Reply: Rob Williscroft: "Re: Template Specialization, subclassing and overriding"
- Reply: Martijn Lievaart: "Re: Template Specialization, subclassing and overriding"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 8 Feb 2004 00:23:14 +1100
"Rob Williscroft" <rtw@freenet.REMOVE.co.uk> wrote in message
news:Xns948886A46F105ukcoREMOVEfreenetrtw@195.129.110.200
> Massimiliano Alberti wrote in
> news:567a3a9.0402070017.1a87a67c@posting.google.com:
>
>> Can I specialize a template function in a subclass without overriding
>> it? (the main template function is defined in a base class).
>> Now I'm doing something like that:
>>
>> (in base class)
>> template<class X>
>> void myfunc(X par1) { }
>>
>> (in derived class)
>> template<class X>
>> void myfunc(X par1) { baseClass::myfunc(par1); } // where baseClass
>> is a typedef with the name of the baseclass
>>
>
> This isn't a specialization:
>
>> void myfunc(AClass par1) { }
>>
>
> One way or another you have to prevent the declaration in derived
> from hiding the declaration in baseClass. The way you've done it
> is fine, but you should also be able to hoist the baseClass version
> (and also any overloads in baseClass) into the derived class with:
>
> using baseClass::myfunc;
>
> HTH.
>
> Rob.
The following does not compile with either VC++ 7.1 or Comeau:
class AClass
{};
class base
{
protected:
template<class X>
void myfunc(X par1) { }
};
class derived : public base
{
using base::myfunc;
template<>
void myfunc<AClass>(AClass par1) { }
};
int main()
{
return 0;
}
The Comeau error message is:
"explicit specialization is not allowed in the current scope"
-- John Carson 1. To reply to email address, remove donald 2. Don't reply to email address (post here instead)
- Next message: zero: "Overriding Methods"
- Previous message: David Rasmussen: "Re: No call for Ada (was Re: Announcing new scripting/prototyping language)"
- In reply to: Rob Williscroft: "Re: Template Specialization, subclassing and overriding"
- Next in thread: Rob Williscroft: "Re: Template Specialization, subclassing and overriding"
- Reply: Rob Williscroft: "Re: Template Specialization, subclassing and overriding"
- Reply: Martijn Lievaart: "Re: Template Specialization, subclassing and overriding"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|