C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: initializer form

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
John Potter
Guest





PostPosted: Fri Jun 27, 2003 4:48 pm    Post subject: Re: initializer form Reply with quote



On 26 Jun 2003 10:15:52 -0400, "Andrei Alexandrescu"
<SeeWebsiteForEmail (AT) moderncppdesign (DOT) com> wrote:

Quote:
"John Potter" <jpotter (AT) falcon (DOT) lhup.edu> wrote in message
news:saljfvci4u0qura56gr7kbm69ldo4ernn7 (AT) 4ax (DOT) com...
Never use the assignment symbol for initialization, it confuses
too many beginners.

Sure I must've misunderstood something. I see nothing confusing about:

int i = 5;
float f = 6;
string s = "Wyda!";

FAQ: Why aren't the default ctor and assignment operator called?

John

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
llewelly
Guest





PostPosted: Sat Jun 28, 2003 11:26 pm    Post subject: Re: initializer form Reply with quote



John Potter <jpotter (AT) falcon (DOT) lhup.edu> writes:

Quote:
On 26 Jun 2003 10:15:52 -0400, "Andrei Alexandrescu"
[email]SeeWebsiteForEmail (AT) moderncppdesign (DOT) com[/email]> wrote:

"John Potter" <jpotter (AT) falcon (DOT) lhup.edu> wrote in message
news:saljfvci4u0qura56gr7kbm69ldo4ernn7 (AT) 4ax (DOT) com...
Never use the assignment symbol for initialization, it confuses
too many beginners.

Sure I must've misunderstood something. I see nothing confusing about:

int i = 5;
float f = 6;
string s = "Wyda!";

FAQ: Why aren't the default ctor and assignment operator called?
[snip]


Unfortunately, for types convertible to bool, there is a place where
constructor style initialization cannot be used:

if(int i(foo)) //syntax error
{
/* ... */
}

if(int i= foo) //ok
{
/* ... */
}



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ed Avis
Guest





PostPosted: Sun Jun 29, 2003 2:03 pm    Post subject: Re: initializer form Reply with quote



llewelly <llewelly.at (AT) xmission (DOT) dot.com> writes:

Quote:
Unfortunately, for types convertible to bool, there is a place where
constructor style initialization cannot be used:

if(int i(foo)) //syntax error
{
/* ... */
}

if(int i= foo) //ok
{
/* ... */
}

That seems really unfortunate, given the mistake (made occasionally by
even experienced programmers) of writing = for == or vice versa. If
the first form were legal then compilers could warn about the second.

What syntactic problem arises if the constructor style is permitted?

--
Ed Avis <ed (AT) membled (DOT) com>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
llewelly
Guest





PostPosted: Mon Jun 30, 2003 4:00 pm    Post subject: Re: initializer form Reply with quote

Ed Avis <ed (AT) membled (DOT) com> writes:

Quote:
llewelly <llewelly.at (AT) xmission (DOT) dot.com> writes:

Unfortunately, for types convertible to bool, there is a place where
constructor style initialization cannot be used:

if(int i(foo)) //syntax error
{
/* ... */
}

if(int i= foo) //ok
{
/* ... */
}

That seems really unfortunate, given the mistake (made occasionally by
even experienced programmers) of writing = for == or vice versa. If
the first form were legal then compilers could warn about the second.

What syntactic problem arises if the constructor style is permitted?

I do not know of any, except the most vexing parse, which is always an
issue with constructor style, in or out of an if. I think this
case was simply overlooked.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
KIM Seungbeom
Guest





PostPosted: Tue Jul 01, 2003 8:19 am    Post subject: Re: initializer form Reply with quote

Ed Avis <ed (AT) membled (DOT) com> wrote

Quote:
llewelly <llewelly.at (AT) xmission (DOT) dot.com> writes:

Unfortunately, for types convertible to bool, there is a place where
constructor style initialization cannot be used:

if(int i(foo)) //syntax error
{
/* ... */
}

if(int i= foo) //ok
{
/* ... */
}

That seems really unfortunate, given the mistake (made occasionally by
even experienced programmers) of writing = for == or vice versa. If
the first form were legal then compilers could warn about the second.

What is the problem with the second approach?
If you use == instead of = by mistake, it will be a syntax error.

if (int i == foo) // error
{ /* ... */

Quote:

What syntactic problem arises if the constructor style is permitted?

I don't see any problem.

--
KIM Seungbeom <musiphil (AT) bawi (DOT) org>

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.