Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: template ty...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 43070 of 48417
Post > Topic >>

Re: template typename parameter cannot be "void"?

by tragomaskhalos <dave.du.vergier@[EMAIL PROTECTED] > Feb 3, 2008 at 03:27 PM

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.
 




 4 Posts in Topic:
template typename parameter cannot be "void"?
Sylvain Guilley <sylva  2008-02-03 14:35:02 
Re: template typename parameter cannot be "void"?
peter koch <peter.koch  2008-02-03 05:50:07 
Re: template typename parameter cannot be "void"?
Sylvain Guilley <sylva  2008-02-03 19:08:34 
Re: template typename parameter cannot be "void"?
tragomaskhalos <dave.d  2008-02-03 15:27:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:48:27 CST 2008.