operator overloading

M

mangesh

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 .
 
Y

Ye Dafeng

mangesh said:
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
 
M

Michal Nazarewicz

mangesh said:
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].
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top