Q:

C++ - Accessing member functions from a map of object pointers, in a seperate class via getter functions

I'm fairly new to C++, I've tried to figure this out on my own but can't quite get there.
I've defined a map of pointers to a group of dynamically allocated objects in one class, with strings as the keys, along with two iterators (begin() and end()), and two getter functions corresponding to each iterator.
class a{

   std::map<string, Fruit*> fruitSalad;
   std::map<string, Fruit*>::iterator begin = fruitSalad.begin(), end = fruitSalad.end();

   std::map<string, Fruit*>::iterator getBeginIter() const; 
   std::map<string, Fruit*>::iterator getEndIter() const;

};

the objects referenced in the map, and their member functions need to be accessible in a separate driver class. To test my implementation I've been trying to print values from the objects with a for loop, by accessing the iterators via their accessors, as shown in the code below.
#include "a.h"

int main(){

   A fruitBowl;

   std::map<string, Object*>::iterator iter;

   for(iter = fruitBowl.getBeginIter(); iter != fruitBowl.getEndIter(); iter++){

      cout << iter.getName() << " " << iter.getQuantity() << endl;
   }
}

But I am getting the following error
error: 'std::map<std::basic_string<char>, Fruit*>:: iterator' has no member named getName()

error: 'std::map<std::basic_string<char>, Fruit*>:: iterator' has no member named getQuantity()

I assume I'm doing something wrong with the assignment of the iterators in my driver class, but what exactly am I doing wrong?

A:

First, when you write iter = fruitBowl.getBeginIter();,  iter is an iterator. This is a pointer-like object. If you want to access the method of the pointed-to object, you must first dereference it.
Second, the objects contained in the std::map<foo, bar> are std::pairs of foo, bar.
So the usage looks like
for(iter = fruitBowl.getBeginIter(); iter != fruitBowl.getEndIter(); iter++){
  auto pFruit = (*iter).second;

  cout << (*pFruit).getName() << " " 
       << (*pFruit).getQuantity() << endl;
}

The first dereference is to access the value of the key-value pair in the map;
the second one is to access the Fruit referenced by the pointer.
Or, using the  syntactic sugar for pointer manipulation:
for(iter = fruitBowl.getBeginIter(); iter != fruitBowl.getEndIter(); iter++){
 auto pFruit = iter->second;

  cout << pFruit->getName() << " " 
       << pFruit->getQuantity() << endl;
}

