Sep 21, 2016 at 8:20am
GetB returns a copy of the list. When you call it in your loop, the begin and end calls are on different lists, so an iterator makes no sense.
Can either take a copy of the list then iterator over that:
1 2 3
|
auto listInstance = a1->GetB();
. . .
for (list<B*>::iterator iter = listInstance.begin(); iter != listInstance.end(); ++iter)
| |
Or avoid the copy all together with a reference:
1 2 3 4 5 6
|
const list<B*>& GetB() const
. . .
for (list<B*>::const_iterator iter = a1->GetB().begin(); iter != a1->GetB().end(); ++iter)
{
cout << (*iter)->Get() << endl;
}
| |
Last edited on Sep 21, 2016 at 8:24am