Thread View: comp.std.c++
5 messages
5 total messages
Started by Roman Lechtchinsky
Fri, 19 Apr 1996 00:25
Member templates
Author: Roman Lechtchinsky
Date: Fri, 19 Apr 1996 00:25
Date: Fri, 19 Apr 1996 00:25
28 lines
1399 bytes
1399 bytes
Hi,
the question is about member templates and virtual functions. I know these
are prohibited. However, what about the following example:
class Base
{
virtual void f(int);
};
class Derived : Base
{
template<class T> void f(T);
};
Is this legal? If so, will the template function f(int) override
Base::f(int)? If so, when will it be instantiated? And, last but not least,
which section of the DWP handles this case? Thanks in advance.
Bye
Roman
---
[ 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 ]
Re: Member templates
Author: David Vandevoorde
Date: Fri, 19 Apr 1996 17:14
Date: Fri, 19 Apr 1996 17:14
32 lines
1977 bytes
1977 bytes
>>>>> "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).
Daveed
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Re: Member templates
Author: Srinivas Vobilisetti
Date: Sat, 20 Apr 1996 15:45
Date: Sat, 20 Apr 1996 15:45
15 lines
1502 bytes
1502 bytes
Though this is not supported before, the DWP supports it. Obvious it behaves like a normal template function and will be instantiated only when it is first invoked. Also template function f(int) will override and f(T) when T != int will hide the base class f(int). I don't remember the exact DWP section numbers. I am not sure whether it will exhibit run-time binding. Srinivas Vobilisetti [ 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 ]
Re: Member templates
Author: Roman Lechtchinsky
Date: Sat, 20 Apr 1996 16:16
Date: Sat, 20 Apr 1996 16:16
47 lines
2266 bytes
2266 bytes
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).
>
IMO, this means that f cannot be overridden in Derived:
class Derived : Base
{
template<class T> void f(T);
void f(int);
};
would be a specialization which means that f doesn't override as it is still
a template ( [temp.over.spec] 14.10.5 ). Is this interpretation correct?
Bye
Roman
---
[ 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 ]
Re: Member templates
Author: 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 ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads