<?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[return problem mit std::map]]></title><description><![CDATA[<pre><code class="language-cpp">class Rect
{
  int x, y, w, h;
public:
Rect(int xx,int yy,int ww,int hh);
}
Rect::Rect(int xx, int yy, int ww, int hh):
    x(xx),
    y(yy),
    w(ww),
    h(hh)
{}

std::map&lt;const char,Rect&gt; rect_map
void set(std::string str, Rect rect){
   rect_map.insert ( std::pair&lt;const char,Rect&gt;(*str.c_str(),rect) );
}
Rect get(std::string str){
     return rect_map[*str.c_str()];
}
</code></pre>
<p>fehler meldung:<br />
../stl_map.h: In member function »_Tp&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const _Key&amp;) [with _Key = const char, _Tp = Rect, _Compare = std::less&lt;const char&gt;, _Alloc = std::allocator&lt;std::pair&lt;const char, Rect&gt; &gt;]«:</p>
<p>19: instantiated from here<br />
../stl_map.h:348: Fehler: keine passende Funktion für Aufruf von »Rect::Rect()«<br />
5: Anmerkung: Kandidaten sind: Rect::Rect(Sint16, Sint16, Uint16, Uint16)<br />
2: Anmerkung: Rect::Rect(const Rect&amp;)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/203345/return-problem-mit-std-map</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 17:08:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/203345.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 21 Jan 2008 19:31:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 19:32:55 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class Rect
{
  int x, y, w, h;
public:
Rect(int xx,int yy,int ww,int hh);
}
Rect::Rect(int xx, int yy, int ww, int hh):
    x(xx),
    y(yy),
    w(ww),
    h(hh)
{}

std::map&lt;const char,Rect&gt; rect_map
void set(std::string str, Rect rect){
   rect_map.insert ( std::pair&lt;const char,Rect&gt;(*str.c_str(),rect) );
}
Rect get(std::string str){
     return rect_map[*str.c_str()];
}
</code></pre>
<p>fehler meldung:<br />
../stl_map.h: In member function »_Tp&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const _Key&amp;) [with _Key = const char, _Tp = Rect, _Compare = std::less&lt;const char&gt;, _Alloc = std::allocator&lt;std::pair&lt;const char, Rect&gt; &gt;]«:</p>
<p>19: instantiated from here<br />
../stl_map.h:348: Fehler: keine passende Funktion für Aufruf von »Rect::Rect()«<br />
5: Anmerkung: Kandidaten sind: Rect::Rect(Sint16, Sint16, Uint16, Uint16)<br />
2: Anmerkung: Rect::Rect(const Rect&amp;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440879</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Mon, 21 Jan 2008 19:32:55 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 19:49:50 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Dir fehlt in der Rect-Klasse einfach ein default-Konstruktor. Den benötigt map nunmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440887</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 21 Jan 2008 19:49:50 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 19:56:06 GMT]]></title><description><![CDATA[<p>geht das auch der der default konstruktor im privat bereich bleibt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440890</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Mon, 21 Jan 2008 19:56:06 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 20:01:13 GMT]]></title><description><![CDATA[<p>map sollte ihn schon aufrufen können. Also nein.<br />
Das Problem beim operator[] von map ist, falls du einen key angibst, der noch nicht in der map ist wird ein neues Objekt erzeugt. Dazu brauchts den default-Konstruktor.<br />
Warum willst du hier überhaupt eine map nehmen wenn du als Index nur einen char hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440892</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 21 Jan 2008 20:01:13 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 20:05:45 GMT]]></title><description><![CDATA[<p>eigentlich soll der index ein string sein</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440897</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Mon, 21 Jan 2008 20:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 20:25:09 GMT]]></title><description><![CDATA[<p>kiba91 schrieb:</p>
<blockquote>
<p>eigentlich soll der index ein string sein</p>
</blockquote>
<p>Das steht da aber nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440908</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Mon, 21 Jan 2008 20:25:09 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Mon, 21 Jan 2008 22:51:55 GMT]]></title><description><![CDATA[<p>Konrad Rudolph schrieb:</p>
<blockquote>
<p>kiba91 schrieb:</p>
<blockquote>
<p>eigentlich soll der index ein string sein</p>
</blockquote>
<p>Das steht da aber nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
</blockquote>
<p>Vielleicht hat er std::map&lt;std::string ,Rect&gt; auf std::map&lt;const char,Rect&gt; &quot;optimiert&quot; weil letzteres schneller läuft <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1440977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1440977</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 21 Jan 2008 22:51:55 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Tue, 22 Jan 2008 07:10:01 GMT]]></title><description><![CDATA[<p>kiba91 schrieb:</p>
<blockquote>
<p>eigentlich soll der index ein string sein</p>
</blockquote>
<p>Ist er aber nicht - ein String ist std::string (zur Not auch &quot;const char*&quot;, aber da mußt du dein Sortierkriterium selber dazubasteln), dein &quot;const char&quot; ist ein einzelnes Zeichen (und das &quot;const&quot; an der Stelle ist überflüssig).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441039</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 22 Jan 2008 07:10:01 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Wed, 23 Jan 2008 11:16:23 GMT]]></title><description><![CDATA[<p>gibt es den keine möglichkeit<br />
das ich den default konstuktor auf private setze und std::map immer noch dadrauf zu greifen kann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441888</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Wed, 23 Jan 2008 11:16:23 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Wed, 23 Jan 2008 11:19:39 GMT]]></title><description><![CDATA[<p>Nein, geht nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1441890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441890</guid><dc:creator><![CDATA[*john 0]]></dc:creator><pubDate>Wed, 23 Jan 2008 11:19:39 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Wed, 23 Jan 2008 11:26:08 GMT]]></title><description><![CDATA[<p>Nicht wirklich (eventuell mit friend-Zugriff, aber davon wird dir jeder erfahrene Programmierer abraten). Du könntest natürlich auch deine get()-Funktion so umstellen, daß sie ohne den Index-Zugriff auskommt:</p>
<pre><code class="language-cpp">Rect get(const std::string&amp; str)
{
  map&lt;string,Rect&gt;::iterator pos = rect_map.find(str);//daß du lieber map&lt;string,Rect&gt; nehmen solltest, wurde schon erwähnt, oder?
  if(pos == rect_map.end())
  {
    //ungütliger Name - hier kannst du dich austoben
    throw std::runtime_error(&quot;ungültiger Name&quot;);
  }
  else
    return pos-&gt;second;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1441894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1441894</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 23 Jan 2008 11:26:08 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Wed, 23 Jan 2008 18:43:46 GMT]]></title><description><![CDATA[<blockquote>
<p>eventuell mit friend-Zugriff, aber davon wird dir jeder erfahrene Programmierer abraten</p>
</blockquote>
<p>wieso abraten?</p>
<p>p.S.: ja, ok, bei näherer Betrachtung erscheint es mir &quot;abratenswert&quot; (*g*), weil man durch den map-friend und map::operator[] die Möglichkeit hat den ctor &quot;hinten herum&quot; auszuführen und zu einem default konstruierten Element zu kommen. Und wenn es auf die Art geht dann sollte es gleich auch &quot;normal&quot; gehen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442254</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442254</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 23 Jan 2008 18:43:46 GMT</pubDate></item><item><title><![CDATA[Reply to return problem mit std::map on Thu, 24 Jan 2008 07:01:40 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>p.S.: ja, ok, bei näherer Betrachtung erscheint es mir &quot;abratenswert&quot; (*g*), weil man durch den map-friend und map::operator[] die Möglichkeit hat den ctor &quot;hinten herum&quot; auszuführen und zu einem default konstruierten Element zu kommen. Und wenn es auf die Art geht dann sollte es gleich auch &quot;normal&quot; gehen...</p>
</blockquote>
<p>Genau darum <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ich gehöre zwar nicht zu den Leuten, die &quot;friend&quot; komplett verteufeln. Aber ich überlege mir grundsätzlich genau, wem ich friend-Zugriff gebe - und das mache ich nur bei Klassen/Funktionen, von denen ich genau weiß, wie sie mit ihren erweiterten Rechten umgehen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1442491</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1442491</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 24 Jan 2008 07:01:40 GMT</pubDate></item></channel></rss>