Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > operator overloading

Reply
Thread Tools

operator overloading

 
 
mangesh
Guest
Posts: n/a
 
      08-29-2006
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 .

 
Reply With Quote
 
 
 
 
Ye Dafeng
Guest
Posts: n/a
 
      08-29-2006
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
 
Reply With Quote
 
 
 
 
Michal Nazarewicz
Guest
Posts: n/a
 
      08-29-2006
"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--
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
overloading operator->*() and operator->() gob00st@googlemail.com C++ 2 02-21-2009 04:26 AM
overloading operator->*() and operator->() gob00st@googlemail.com C++ 11 02-20-2009 08:52 PM
user defined conversion operator or operator overloading? hurcan solter C++ 3 08-29-2007 07:39 PM
Why is overloading operator. (member operator) forbidden? dascandy@gmail.com C++ 11 05-16-2007 07:54 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57