0

I've defined my own class and stored objects of them in a std:list. Now I want to pick up all the elements, but something went wrong - I hope this is not too complicated to read:

std::map < long, FirstClass*> FirstClassMap;
std::map < long, FirstClass* >::iterator it;
it=this->FirstClassMap.begin() 
//initialization of FirstClassMap is somewhere else and shouldn't matter.

list<SecondClass*>::iterator ListItem;
list<SecondClass*> depList = it->second->getSecondClassList();

for(ListItem = depList.begin(); ListItem != depList.end(); ++ListItem)
{
    /* -- the error is in this Line -- */
    FirstClass* theObject = ListItem->getTheListObject();
    std::cout << theObject->Name();
}

Then there is the function:

SecondClass::getTheListObject()
{
    return this->theObject; //returns a FirstClass object
}

FirstClass::Name()
{
    return this->name //returns a string
}

Here I get the Error

Method 'getTheListObject' could not be resolved

and

Error:element request »getTheListObject« in »* ListItem.std::_List_iterator<_Tp>::operator->()«, whose pointer type is »SecondClass*« (maybe »->« was meant)

(I'm sorry, that I can't give you the correct error message. I have to translate it from German to English, I don't get these in English)

I don't really see the problem. Has anyone an idea?

Kind Regards

user3085931
  • 1,757
  • 4
  • 29
  • 55
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – πάντα ῥεῖ Jun 27 '14 at 06:55
  • @πάνταῥεῖ no this is not about an external symbol error – user3085931 Jun 27 '14 at 06:58
  • 3
    Try `FirstClass* theObject = (*ListItem)->getTheListObject();`, you have to dereference the iterator, to access the list element. – πάντα ῥεῖ Jun 27 '14 at 07:00
  • it is thanks I've tried many combinations of the *, it's always the small errors ;) thank you – user3085931 Jun 27 '14 at 07:09

1 Answers1

2

In your code, ListItem isn't an instance of SecondClass*, it's an instance of an iterator of SecondClass*. You have to dereference the iterator to get access to the underlying object. So your for loop should look like:

for(ListItem = depList.begin(); ListItem != depList.end(); ++ListItem)
{
    FirstClass* theObject = (*ListItem)->getTheListObject(); //Dereference the iterator, 
                                                             //then call the method.
    std::cout << theObject->Name();
}
Rakib
  • 7,435
  • 7
  • 29
  • 45
dustyrockpyle
  • 3,184
  • 17
  • 12