Wrong Constructor Called

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeffc

    #16
    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.


    Comment

    • Ron Natalie

      #17
      Re: Wrong Constructor Called


      "jeffc" <nobody@nowhere .com> wrote in message news:4010050d_3 @news1.prserv.n et...[color=blue]
      >
      > 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.[/color]

      Well the real culprit is the array-to-pointer translation. Frankly, I think that
      was a mistake. If people wanted a pointer to the first element, they should
      be forced to do something like &x[0]. That and arrays should work like
      all the other data types:
      int x[3] = { 0, 1, 2};
      int y[3];

      y = x;
      etc...

      Comment

      • jeffc

        #18
        Re: Wrong Constructor Called


        "Ron Natalie" <ron@sensor.com > wrote in message
        news:4010138e$0 $82872$9a6e19ea @news.newshosti ng.com...[color=blue]
        >
        > "jeffc" <nobody@nowhere .com> wrote in message[/color]
        news:4010050d_3 @news1.prserv.n et...[color=blue][color=green]
        > >
        > > Yeah, I understand your point. It just seems to me that when a compiler[/color][/color]
        can[color=blue][color=green]
        > > distinguish between a literal and a pointer, it should. To put it[/color][/color]
        another[color=blue][color=green]
        > > way, I don't see why a string literal has to blindly be treated like a
        > > pointer in all cases.[/color]
        >
        > Well the real culprit is the array-to-pointer translation. Frankly, I[/color]
        think that[color=blue]
        > was a mistake. If people wanted a pointer to the first element, they[/color]
        should[color=blue]
        > be forced to do something like &x[0].[/color]

        I also don't see any problem with that.


        Comment

        Working...