<?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[const iterator]]></title><description><![CDATA[<p>Ich habe eine Frage zu diesem Code:</p>
<pre><code class="language-cpp">Object*	Dev::getObject(const std::string&amp; name) const {
	ObjectMap::const_iterator it = objs.find(name);  
	return it != objs.end() ? it-&gt;second : NULL;
}
</code></pre>
<p>Da meckert mein Compiler:</p>
<blockquote>
<p>error C2440: 'initializing' : cannot convert from 'std::_Tree&lt;_Traits&gt;::const_iterator' to 'std::_Tree&lt;_Traits&gt;::iterator'</p>
</blockquote>
<p>Der Grund ist wohl, dass find() einen const_iterator liefert. Ich verstehe nur nicht warum. meine map objs ist eine ganz normale map und keine const map.<br />
Ich dachte das läuft so in C++:</p>
<pre><code class="language-cpp">Foo f;
const Foo cf;
f.bar();  // ruft Foo::bar() auf
cf.bar(); // ruft Foo::bar() const auf
</code></pre>
<p>Aber wieso wird bei mir find() const aufgerufen, wenn map nicht konstant ist? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/246536/const-iterator</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 01:51:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/246536.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 Jul 2009 15:08:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:08:13 GMT]]></title><description><![CDATA[<p>Ich habe eine Frage zu diesem Code:</p>
<pre><code class="language-cpp">Object*	Dev::getObject(const std::string&amp; name) const {
	ObjectMap::const_iterator it = objs.find(name);  
	return it != objs.end() ? it-&gt;second : NULL;
}
</code></pre>
<p>Da meckert mein Compiler:</p>
<blockquote>
<p>error C2440: 'initializing' : cannot convert from 'std::_Tree&lt;_Traits&gt;::const_iterator' to 'std::_Tree&lt;_Traits&gt;::iterator'</p>
</blockquote>
<p>Der Grund ist wohl, dass find() einen const_iterator liefert. Ich verstehe nur nicht warum. meine map objs ist eine ganz normale map und keine const map.<br />
Ich dachte das läuft so in C++:</p>
<pre><code class="language-cpp">Foo f;
const Foo cf;
f.bar();  // ruft Foo::bar() auf
cf.bar(); // ruft Foo::bar() const auf
</code></pre>
<p>Aber wieso wird bei mir find() const aufgerufen, wenn map nicht konstant ist? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751740</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751740</guid><dc:creator><![CDATA[audicupvorfreuer]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:08:13 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:13:06 GMT]]></title><description><![CDATA[<p>Wenn objs ein Member der Klasse Dev ist, ist es const, weil this const ist (und das ist es, weil Du const am Ende des Funktionskopfes von Dev::getObject notierst).</p>
<p>Die Fehlermeldung verstehe ich trotzdem nicht, da sowohl find() const als auch end() const einen const_iterator zurückliefern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751742</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:13:06 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:16:41 GMT]]></title><description><![CDATA[<p>Die Fehlermeldung an sich find ich auch komisch, aber wenn man nen bissl was rauskürzt, sieht man sehr gut, was passiert:</p>
<pre><code class="language-cpp">Object*    Dev::getObject(const std::string&amp; name) const { 
    ObjectMap::const_iterator it;
    return it-&gt;second;
}
</code></pre>
<p>const_iterator gibt nur ein <code>const Object*</code> wieder...<br />
schreib also einfach const Object* oder mach die fkt nicht const und schreib iterator...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751748</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751748</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:16:41 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:17:49 GMT]]></title><description><![CDATA[<p>Grundsätzlich richtig, aber sollte dann die Fehlermeldung nicht lauten &quot;cannot convert from const Object* to Object*&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751750</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:17:49 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:19:56 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>Grundsätzlich richtig, aber sollte dann die Fehlermeldung nicht lauten &quot;cannot convert from const Object* to Object*&quot;?</p>
</blockquote>
<p>hätte ich deshalb eben auch erwartet - und hab deshalb auch komische fehlermeldung geschrieben...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751752</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:19:56 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:25:52 GMT]]></title><description><![CDATA[<p>Das heißt also, dass weil die Methode const ist, this vom Typ const T* const ist und ich somit NUR const Methoden über this aufrufen kann, richtig? Sprich:<br />
this-&gt;bar() geht nur, wenn bar() const ist?</p>
<p>Zu der Fehlermeldung: Ich hatte in meinem Code einen kleinen Fehler, denn statt ObjectMap::const_iterator stand da eigentlich ObjectMap::iterator.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751756</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751756</guid><dc:creator><![CDATA[audicupvorfreuer]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:25:52 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 15:33:26 GMT]]></title><description><![CDATA[<p>audicupvorfreuer schrieb:</p>
<blockquote>
<p>Das heißt also, dass weil die Methode const ist, this vom Typ const T* const ist und ich somit NUR const Methoden über this aufrufen kann, richtig? Sprich:<br />
this-&gt;bar() geht nur, wenn bar() const ist?</p>
</blockquote>
<p>Jap. Genauergesagt ist this vom Typ Dev const* const und alle Member sind ebenfalls const (auf oberster Ebene). Sprich, Du kannst auch auf Member der Klasse nur const-Methoden aufrufen.</p>
<blockquote>
<p>Zu der Fehlermeldung: Ich hatte in meinem Code einen kleinen Fehler, denn statt ObjectMap::const_iterator stand da eigentlich ObjectMap::iterator.</p>
</blockquote>
<p>Dann ergibt die Meldung schlagartig Sinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751760</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 29 Jul 2009 15:33:26 GMT</pubDate></item><item><title><![CDATA[Reply to const iterator on Wed, 29 Jul 2009 16:22:46 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<blockquote>
<p>Zu der Fehlermeldung: Ich hatte in meinem Code einen kleinen Fehler, denn statt ObjectMap::const_iterator stand da eigentlich ObjectMap::iterator.</p>
</blockquote>
<p>Dann ergibt die Meldung schlagartig Sinn.</p>
</blockquote>
<p>Richtig - wann lernen die Leute es eigtl endlich, mal den Code zu kopieren statt abzutippen und dabei noch 100 Fehler reinzumachen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f623.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--persevering_face"
      title="&gt;.&lt;"
      alt="😣"
    /></p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1751777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1751777</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 29 Jul 2009 16:22:46 GMT</pubDate></item></channel></rss>