<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Dear all,</div><div>I am quite new to the lemon community.</div><div><br></div><div>I've been trying to create a NodeFilter adapter to filter some of the nodes, and then iterate through the remaining nodes. I've come across a bug which I simply can't understand and would appreciate your help. I use lemon 1.2.2 (stable).</div><div><br></div><div>When running the following code:</div><div><br></div><div>SmartGraph g;<br>for(int i = 0; i < 5; i++) { g.addNode(); }<br>SmartGraph::NodeMap<bool> filter(g, true);<br>FilterNodes<SmartGraph> *filtered_g = new FilterNodes<SmartGraph>(g, filter);<br>for(FilterNodes<SmartGraph>::NodeIt n(*filtered_g); n != INVALID; ++n)<br> cout << "I am in node " << g.id(n) << endl;<br></div><div><br></div><div>I get the expected
result. HOWEVER, when I replace the line that defines filtered_g with:</div><div>FilterNodes<SmartGraph> *filtered_g = foo(g);</div><div><br></div><div>with:</div><div>FilterNodes<SmartGraph>* foo(SmartGraph& g)<br>{<br> SmartGraph::NodeMap<bool> filter(g, true);<br> return new FilterNodes<SmartGraph>(g, filter);<br>}</div><div><br></div><div>I get unexpected results (sometimes segmentation errors, sometimes the iterator runs only on a subset of the vertices - depends on the input graph I generate).</div><div>Can someone please explain to me what's going on here? Shouldn't both pieces of code be completely equivalent?</div><div><br></div><div>Thanks much,</div><div>Pete<br></div></div></body></html>