<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[std::max_element(...)]]></title><description><![CDATA[<p>hallo!</p>
<p>ich möchte mithilfe von max_element das älteste tier herausfinden.<br />
wir sollen Polymorphi verwenden:</p>
<pre><code class="language-cpp">vector&lt;animal*&gt; tiere;

    cow c(&quot;Birgit&quot;, dat, 12.2, 80.0, 4, 30.6, 10.6, 10.5 );
    animal* a1= &amp;c;
    tiere.push_back(a1);
    ausgabe(a1);

    chicken ch(&quot;Iris&quot;, dat, 12.2, 80.0, 2, 20, 123.6, 55.5 );
    animal* a2 = &amp;ch;
    tiere.push_back(a2);
    ausgabe(a2);

animal* oldest = std::max_element(*tiere.begin(), *tiere.end(),alt);

}

bool alt(animal i, animal j)
{
  datum* a = i.gebdatum();
  datum* b = j.gebdatum();
  return(bool) (&amp;a&lt;&amp;b);

}
</code></pre>
<p>Ich erhalte nun einen Segfault. Der hund ist dahin begraben, dass ich die animals als Zeiger speichere. Wie kann ich nun auf diese in max_element richtig zugreifen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/305187/std-max_element</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 02:20:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/305187.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Jun 2012 12:05:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::max_element(...) on Sat, 23 Jun 2012 12:06:04 GMT]]></title><description><![CDATA[<p>hallo!</p>
<p>ich möchte mithilfe von max_element das älteste tier herausfinden.<br />
wir sollen Polymorphi verwenden:</p>
<pre><code class="language-cpp">vector&lt;animal*&gt; tiere;

    cow c(&quot;Birgit&quot;, dat, 12.2, 80.0, 4, 30.6, 10.6, 10.5 );
    animal* a1= &amp;c;
    tiere.push_back(a1);
    ausgabe(a1);

    chicken ch(&quot;Iris&quot;, dat, 12.2, 80.0, 2, 20, 123.6, 55.5 );
    animal* a2 = &amp;ch;
    tiere.push_back(a2);
    ausgabe(a2);

animal* oldest = std::max_element(*tiere.begin(), *tiere.end(),alt);

}

bool alt(animal i, animal j)
{
  datum* a = i.gebdatum();
  datum* b = j.gebdatum();
  return(bool) (&amp;a&lt;&amp;b);

}
</code></pre>
<p>Ich erhalte nun einen Segfault. Der hund ist dahin begraben, dass ich die animals als Zeiger speichere. Wie kann ich nun auf diese in max_element richtig zugreifen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226430</guid><dc:creator><![CDATA[nero08]]></dc:creator><pubDate>Sat, 23 Jun 2012 12:06:04 GMT</pubDate></item><item><title><![CDATA[Reply to std::max_element(...) on Sat, 23 Jun 2012 12:18:02 GMT]]></title><description><![CDATA[<p>Deine Vergleichsfunktion muss den gleichen Typen annehmen, wie im Container gespeichert sind. Also Zeiger auf animal.</p>
<p>edit: Und du darfst beim Aufruf von max_element natürlich nicht die Iteratoren dereferenzieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226434</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 23 Jun 2012 12:18:02 GMT</pubDate></item><item><title><![CDATA[Reply to std::max_element(...) on Sat, 23 Jun 2012 12:24:13 GMT]]></title><description><![CDATA[<p>ahhh, genau!</p>
<p>das wars jetzt gehts ich danke dir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2226438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2226438</guid><dc:creator><![CDATA[nero08]]></dc:creator><pubDate>Sat, 23 Jun 2012 12:24:13 GMT</pubDate></item></channel></rss>