c++ - How do I let my self-written iterator support ->? -


i writing own iterator in c++:

class my_iterator {   entity operator*() {     ...   }   my_iterator& operator++() {     ...   } } 

i can dereference entity using * operator. however, can let custom iterator support -> operation (followed property or method of dereferenced entity)?

is there operator can implement support ->?

yes, overload -> if want special behavior, otherwise it's standard behavior on pointers.

for case you'll have like

entity* operator->() {     return ptr_to_entity; } 

this odd because -> overload returns pointer object , -> used on that.

eg above makes:

my_iterator_instance->foo === ptr_to_entity->foo 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -