Question: I am creating some stuff on a `.on()` jquery handler like that

```
$('#idhere').on('click', function(){
   //create a couple of divs with a class
   });

```

Now I also want to add an event on the divs created, I have tried:

```
$('.divcreated').bind('mouseover', function(){
   //do some magic
   });

```

For some reason the second event is never triggered probably because they are both asynchronous. Any ideas to trigger the second event?

Answer: 
Think of an iterator as a pointer to an element in the list. So, instead of making the `calc_average` function act on individual members of `mystruct` you may want to have it take a reference to a `mystruct` object and doing something with that.

For instance:

```
void do_work( mystruct& s )
{
  ++s.count;
}

std::list<mystruct> mylist;

// populate list

std::for_each( mylist.begin(), mylist.end(), do_work );

```

You can also achieve the same effect with range based `for` loops

```
for( auto& elem : mylist ) {
  do_work( elem );
}

```

I would rewrite the `calc_average` function as

```
void calc_average( mystruct& s, long quant )
{
    s.avg = ( (s.avg * s.count) + quant ) / (s.count + 1);
    s.count++;
}

```

To use it with range based `for` loops is trivial, but to use it with `std::for_each` you'll have to use `std::bind` to bind the `quant` parameter.

```
std::for_each( mylist.begin(), mylist.end(), 
  std::bind( calc_average, std::placeholders::_1, qty ) );

```
Yes, it all seems correct to me. You can think of iterators (especially iterators of standard containers) as just pointers, though in practice they're actually classes that look like pointers. Still, you can think of them as pointers.