operator overloading

Discussion in 'C++' started by mangesh, Aug 29, 2006.

  1. mangesh

    mangesh Guest

    I have a list implementation in which [] operator has been ocerloaded .
    Now when i have pointer to list say *list_ptr , and i write
    list_ptr[0] .
    Which [] operator will be called ?
    Overloaded or default ?
    I think default [] , but in may case i am not getting result
    accordingly .

    Regards ,
    Mangesh Sawant .
     
    mangesh, Aug 29, 2006
    #1
    1. Advertising

  2. mangesh

    Ye Dafeng Guest

    mangesh wrote:
    > I have a list implementation in which [] operator has been ocerloaded .
    > Now when i have pointer to list say *list_ptr , and i write
    > list_ptr[0] .
    > Which [] operator will be called ?
    > Overloaded or default ?
    > I think default [] , but in may case i am not getting result
    > accordingly .
    >
    > Regards ,
    > Mangesh Sawant .
    >

    i think it uses the overloaded one
     
    Ye Dafeng, Aug 29, 2006
    #2
    1. Advertising

  3. "mangesh" <> writes:

    > I have a list implementation in which [] operator has been ocerloaded .
    > Now when i have pointer to list say *list_ptr , and i write
    > list_ptr[0] .
    > Which [] operator will be called ?
    > Overloaded or default ?


    The default, because you have only overloaded [] for type Foo (where
    Foo is you list class) and *not* for Foo* (which in fact is impossible
    as Foo* is /built-in/ type). To use overloaded [] you have to do:
    (*list_ptr)[0].

    --
    Best regards, _ _
    .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
    ..o | Computer Science, Michal "mina86" Nazarewicz (o o)
    ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
     
    Michal Nazarewicz, Aug 29, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    2
    Views:
    433
    Ivan Vecerina
    Oct 6, 2004
  2. Replies:
    11
    Views:
    749
    James Kanze
    May 16, 2007
  3. hurcan solter
    Replies:
    3
    Views:
    741
    Cholo Lennon
    Aug 29, 2007
  4. Replies:
    11
    Views:
    570
  5. Replies:
    2
    Views:
    323
Loading...

Share This Page