To access an STL iterator, why do I need a scope resolution operator, and not a dot operator? Is it because the iterator is static, and does not belong to a particular class instance?
vector<int>::iterator my_iterator;
and not
vector<int> numbers;
numbers.iterator;
Dot and arrow (->
) operators are used to access all data (member variables, functions) that is specific to the given instance.
Scope resolution operator is used to access all data (static member variables, static functions, types) that is specific to the given type, not instance. Note that member types are never instance-specific so you will always use type::member_type
to access them.
a::b
names a type; a.b
references a variable. In your example, my_iterator
is the variable's name, and vector<int>::iterator
is its type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With