Pointer Interpretation

I have a question regarding pointers. I'm trying to follow some code and see a use of pointers that I'm not quite understanding.

Below is an example of what I'm seeing.
1
2
3
4
5
6
7
8
void dispatch(const std::string& key, const std::string& value)
{

    Map::iterator variable = map.find(key);

    variable->second->function(key, value);

}


I know a little bit about how to interpret "->" but with "second" in there I'm getting a bit confused.

As I understand it "second" copies the second member of the iterator "variable". Is that right?

Can I read it as:

 
(*(*variable).second).function(key, value);


Any help here would be appreciated.
variable is an iterator.
to get to the actual element, you have to dereference the iterator using *. or ->
the actual element in a map<K, V> is a struct std::pair<K, V>.
std::pair<K, V> has two data members named "first" and "second" (first is of type K,
second is of type V)
In your above code, V could be a pointer to an object which has a member function named "function".

a->b can be rewritten as *a.b (in most cases). Apply that rule twice: a->b->c can be rewritten
as (*a.b)->c which can be written as *(*a.b).c
It looks like I was interpreting it correctly. Huzzah!

Thanks.
Topic archived. No new replies allowed.