Just return const reference in adjs()
, it should work. Currently it is returning a copy, hence when you take iterator in (*it)->adjs().begin()
and in (*it)->adjs().end()
, it gives iterators to different copies
const std::list<Node*>& adjs() const { return adjList; }