Topic: void template argument and overriding
Author: pjl@graceland.att.com (Paul J. Lucas)
Date: 1995/04/17 Raw View
Should:
template<class A> struct T {
virtual void f( A ) = 0;
}
struct S : T<void> {
void f() { }
};
have S::f override T::f? I would think so since, after all, f()
is equivalent to f(void). The above makes sense for, say, int;
but what about void? My compiler complains that S::f hides
T::f, but likes:
template<class R> struct T {
virtual R f() = 0;
}
struct S : T<void> {
void f() { }
};
just fine. Does the WP address this?
--
- Paul J. Lucas Paul.J.Lucas@att.com
AT&T Bell Laboratories http://eec.psu.edu/~scott/pjl/
Naperville, IL #include <stddisclaimer.h>
Author: jhs@edg.com (John H. Spicer)
Date: 1995/04/17 Raw View
In article <pjl.798130465@graceland.att.com> pjl@graceland.att.com (Paul J. Lucas) writes:
> Should:
>
> template<class A> struct T {
> virtual void f( A ) = 0;
> }
>
> struct S : T<void> {
> void f() { }
> };
>
> have S::f override T::f? I would think so since, after all, f()
> is equivalent to f(void). The above makes sense for, say, int;
> but what about void?
The example above is ill-formed when A is void. A parameter cannot have
type "void". Only the syntactic construct (void) is equivalent to ().
Other names for void (e.g., typedefs, etc.) cannot be used for this
purpose.
> My compiler complains that S::f hides
> T::f, but likes:
>
> template<class R> struct T {
> virtual R f() = 0;
> }
>
> struct S : T<void> {
> void f() { }
> };
>
> just fine. Does the WP address this?
The WP does. 8.3.5p2.
John Spicer
Edison Design Group
jhs@edg.com