Re: Wrong Constructor Called
"Howard" <alicebt@hotmai l.com> wrote in message
news:bumtn9$mb1 @dispatch.conce ntric.net...[color=blue]
>[color=green]
> >
> > Whaddya know. Personally I don't think that conversion should be[/color][/color]
there -[color=blue]
> it[color=green]
> > seems meaningless for a literal string.
> >
> >[/color]
> It's because a string literal is treated as a const char array, and a
> pointer to that array is created and used. The conversion is then really
> from a char* to a bool, which makes a great deal of sense, since it is
> common to check for a non-null pointer by writing something like
>
> if (pointer_to_som ething){......}[/color]
Yeah, I understand your point. It just seems to me that when a compiler can
distinguish between a literal and a pointer, it should. To put it another
way, I don't see why a string literal has to blindly be treated like a
pointer in all cases. Keep in mind that bools aren't implied in your
example. For example,
if ("asdf")
is one thing, because it doesn't imply conversion to bool. Forcing
conversion to bool specifically is another thing.
"Howard" <alicebt@hotmai l.com> wrote in message
news:bumtn9$mb1 @dispatch.conce ntric.net...[color=blue]
>[color=green]
> >
> > Whaddya know. Personally I don't think that conversion should be[/color][/color]
there -[color=blue]
> it[color=green]
> > seems meaningless for a literal string.
> >
> >[/color]
> It's because a string literal is treated as a const char array, and a
> pointer to that array is created and used. The conversion is then really
> from a char* to a bool, which makes a great deal of sense, since it is
> common to check for a non-null pointer by writing something like
>
> if (pointer_to_som ething){......}[/color]
Yeah, I understand your point. It just seems to me that when a compiler can
distinguish between a literal and a pointer, it should. To put it another
way, I don't see why a string literal has to blindly be treated like a
pointer in all cases. Keep in mind that bools aren't implied in your
example. For example,
if ("asdf")
is one thing, because it doesn't imply conversion to bool. Forcing
conversion to bool specifically is another thing.
Comment