Article View: comp.std.c++
Article #4124Re: Member templates
From: David Vandevoorde
Date: Sun, 21 Apr 1996 07:02
Date: Sun, 21 Apr 1996 07:02
70 lines
3259 bytes
3259 bytes
>>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
RL> David Vandevoorde wrote:
>>
>> >>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
>> [...]
RL> class Base
RL> {
RL> virtual void f(int);
RL> };
>>
RL> class Derived : Base
RL> {
RL> template<class T> void f(T);
RL> };
>>
RL> Is this legal? If so, will the template function f(int) override
RL> Base::f(int)? If so, when will it be instantiated? And, last but not
RL> least, which section of the DWP handles this case? Thanks in advance.
>>
>> I believe this is legal and the instantiated member function is not
>> virtual (i.e., no overriding), but my reason extrapolates the WPs
>> somewhat. I base this on the fact that the `signature' of a template
>> function includes the actual template arguments ([temp.over.link]
>> 14.10.4/3 in the April CD), and that when [class.virtual] 10.3/2
>> requires `same name', `name' really means template-id and not just
>> template-name ([temp.names] 14.1).
>>
RL> IMO, this means that f cannot be overridden in Derived:
RL> class Derived : Base
RL> {
RL> template<class T> void f(T);
RL> void f(int);
RL> };
RL> would be a specialization which means that f doesn't override as it is
^^^^^^^^^^^^^^
To me more precise: it would be a ``guiding member-function declaration'',
if such a beast is supposed to exist (i.e., it declares a specialization,
but only to guide overloading resolution --- the definition is still
generated from the template). However...
RL> still a template ( [temp.over.spec] 14.10.5 ). Is this interpretation
RL> correct?
Frankly, I don't know. I can see three reasonable possibilities:
1) your interpretation,
2) it is not a guiding declaration but an overriding function.
A guiding declaration could instead perhaps be declared via:
struct Derived: Base {
template<typename T>
void f(T);
void f<int>(int); // Guiding member function declaration
void f(int); // Virtual function overriding Base::f(int);
};
3) it is simply illegal C++ code.
I suspect 1) is true, but I'm really not sure at all...
Daveed
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Technical Details
Message-ID:
<xso20li5q6z.fsf@avs.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<31763F3F.805@cs.tu-berlin.de> <xsoivewlve3.fsf@avs.cs.rpi.edu> <3178D6BB.7167@cs.tu-berlin.de>Show Full Headers
Complete Article Headers
From: vandevod@cs.rpi.edu (David Vandevoorde) Message-ID: <xso20li5q6z.fsf@avs.cs.rpi.edu> X-Original-Date: 20 Apr 1996 21:19:33 -0400 Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 21 Apr 96 07:02:43 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Member templates Organization: RPI Computer Science References: <31763F3F.805@cs.tu-berlin.de> <xsoivewlve3.fsf@avs.cs.rpi.edu> <3178D6BB.7167@cs.tu-berlin.de> In-Reply-To: Roman Lechtchinsky's message of 20 Apr 96 16:16:11 GMT X-Newsreader: Gnus v5.1 X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMXndnOEDnX0m9pzZAQFY2AF/TgdEtb8Is8KxxmYBK6i85dwDsPSFyX9u jQrFzdMv61NSRmSCEdd9ic1lO2eftxrx =s8X0