<br><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>Once the function above returns the object "filter" will have been destroyed as it goes out-of-scope, so it is not surprising you get segmentation errors. <br>
<br>You should probably  have something like<br> SmartGraph::NodeMap<bool> *filter=new SmartGraph::NodeMap<bool> (g, true);<br> return new FilterNodes<SmartGraph>(g, *filter);<br></div>But of course you are now responsible for deleting the filter at some point.<br>
<br><div class="gmail_quote">On Thu, Aug 11, 2011 at 10:20 AM, Peter Ka <span dir="ltr"><<a href="mailto:peter_ka@ymail.com">peter_ka@ymail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><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 " << <a href="http://g.id" target="_blank">g.id</a>(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></div><br>_______________________________________________<br>

Lemon-user mailing list<br>
<a href="mailto:Lemon-user@lemon.cs.elte.hu">Lemon-user@lemon.cs.elte.hu</a><br>
<a href="http://lemon.cs.elte.hu/mailman/listinfo/lemon-user" target="_blank">http://lemon.cs.elte.hu/mailman/listinfo/lemon-user</a><br>
<br></blockquote></div><br>