Segmentation fault in list<Object*> iterator : <p>I'm learning C++, and now I have problems with iterators. This is my case: I have this code here.</p>

<pre><code>// std::list&lt;Dragon*&gt; dragons = cave.getDragons();
for (std::list&lt;Dragon*&gt;::iterator it = cave.getDragons().begin(); it != cave.getDragons().end(); it++){
        os &lt;&lt; std::endl &lt;&lt; (*it)-&gt;getName();
}
</code></pre>

<p>It returns a Segmentation fault. This is my list and my getDragons() method:</p>

<pre><code>std::list&lt;Dragon*&gt; dragons;
std::list&lt;Dragon*&gt; getDragons() const {return dragons;}
</code></pre>

<p>And my question is... Why do I have a Segmentation fault doing that like this, but if I use dragons variable, which is commented, don't? Thanks! </p>
