On 3 Feb, 18:08, Sylvain Guilley <sylvain.guil...@[EMAIL PROTECTED]
> wrote:
> peter koch wrote:
> > On 3 Feb., 14:35, Sylvain Guilley <sylvain.guil...@[EMAIL PROTECTED]
> wrote:
> >> Hello,
>
> >> =A0 I am wondering why "typename D" can be anything, a class or a
> >> primitive type (int, float, etc.) but not void?
>
> > But you can - no problem with that.
>
> > The problem with your example is that you can't create a variable of
> > type void, so you have to find an alternative solution (e.g.
> > specialise for void).
>
> > /Peter
>
> Right, a variable cannot be of type void.
>
> However, my problem is that the following two non-template function
> definitions are legal:
>
> void foo( int =A0) { return; }
> void foo( void ) { return; }
>
> but it seems impossible to unify the parameter of foo (either int or
> void) into a template typename. For instance, in this code snippet:
>
Peter's explanation was actually complete -
your confusion stems from the mismatch between semantics and
syntax in this case. Don't think of void foo (void);
as "taking a void parameter", because this is of course
misleading - it's just another way of spelling
void foo (); (as I'm sure you know), provided for
historical reasons of C compatibility. When viewed in
these terms the behaviour of the language is seen to
be sensible and logically correct.


|