| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"mangesh" |
| Date: |
29 Aug 2006 03:33:59 AM |
| Object: |
operator overloading |
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 .
.
|
|
| User: "Michal Nazarewicz" |
|
| Title: Re: operator overloading |
29 Aug 2006 04:28:39 AM |
|
|
"mangesh" <mangesh_sawant@walla.com> 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--
.
|
|
|
|
| User: "Ye Dafeng" |
|
| Title: Re: operator overloading |
29 Aug 2006 03:55:44 AM |
|
|
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
.
|
|
|
|

|
Related Articles |
|
|