<?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::map prob]]></title><description><![CDATA[<pre><code class="language-cpp">class My{
  int x;
  int y;
  My(int,int)
};
My::My(int x2,int y2):x(x2),y(y2){}

class My2{
  std::map&lt;unsigned int,My&gt; xyz;
  void set(unsigned int,My);
}
void My2::set(unsigned int index,My myy){xyz[index] = myy;}  //hier ist der fehler
</code></pre>
<p>fehlermeldung:<br />
..\stl_map.h In member function `_Tp&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const _Key&amp;) [with _Key = unsigned int, _Tp = My, _Compare = std::less&lt;unsigned int&gt;, _Alloc = std::allocator&lt;std::pair&lt;const unsigned int, ;My&gt; &gt;]':</p>
<p>..\stl_map.h no matching function for call to `My::My()'</p>
<p>candidates are: My::My(const My&amp;)<br />
My::My(int, int)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/199899/std-map-prob</link><generator>RSS for Node</generator><lastBuildDate>Sat, 03 Oct 2026 22:38:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/199899.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Dec 2007 11:39:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::map prob on Sat, 08 Dec 2007 11:39:50 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class My{
  int x;
  int y;
  My(int,int)
};
My::My(int x2,int y2):x(x2),y(y2){}

class My2{
  std::map&lt;unsigned int,My&gt; xyz;
  void set(unsigned int,My);
}
void My2::set(unsigned int index,My myy){xyz[index] = myy;}  //hier ist der fehler
</code></pre>
<p>fehlermeldung:<br />
..\stl_map.h In member function `_Tp&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const _Key&amp;) [with _Key = unsigned int, _Tp = My, _Compare = std::less&lt;unsigned int&gt;, _Alloc = std::allocator&lt;std::pair&lt;const unsigned int, ;My&gt; &gt;]':</p>
<p>..\stl_map.h no matching function for call to `My::My()'</p>
<p>candidates are: My::My(const My&amp;)<br />
My::My(int, int)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1416956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1416956</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Sat, 08 Dec 2007 11:39:50 GMT</pubDate></item><item><title><![CDATA[Reply to std::map prob on Sat, 08 Dec 2007 11:49:45 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Deine Klasse my braucht für die Verwendung in STL-Containern einen Standard-Konstruktor ohne Parameter und/oder einen Kopierkonstruktor.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1416964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1416964</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sat, 08 Dec 2007 11:49:45 GMT</pubDate></item><item><title><![CDATA[Reply to std::map prob on Sat, 08 Dec 2007 12:46:43 GMT]]></title><description><![CDATA[<p>Und verwende am besten eine konstante Referenz für deine Parameter:</p>
<pre><code class="language-cpp">void My2::set(unsigned int index, const My &amp;myy) { .. }
</code></pre>
<p>So braucht das Objekt nicht kopiert zu werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1416993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1416993</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Sat, 08 Dec 2007 12:46:43 GMT</pubDate></item><item><title><![CDATA[Reply to std::map prob on Sat, 08 Dec 2007 13:06:31 GMT]]></title><description><![CDATA[<p>akari schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>Deine Klasse my braucht für die Verwendung in STL-Containern einen Standard-Konstruktor ohne Parameter und/oder einen Kopierkonstruktor.</p>
<p>bis bald<br />
akari</p>
</blockquote>
<p>Das ist nicht richtig. Ein Typ für einen Container muss copy-konstruierbar und zuweisbar sein.</p>
<blockquote>
<p>The type of objects stored in these components must meet the requirements of CopyConstructible<br />
types (20.1.3), and the additional requirements of Assignable types.</p>
</blockquote>
<p>Man braucht für map::operator[] einen Defaultkonstruktor (auch hier stimmt nicht, dass er ohne Parameter sein muss), da er folgende Semantik hat:</p>
<blockquote>
<p>return (*((insert(make_pair(x, T()))).first)).second;</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1416998</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1416998</guid><dc:creator><![CDATA[Freundlich]]></dc:creator><pubDate>Sat, 08 Dec 2007 13:06:31 GMT</pubDate></item><item><title><![CDATA[Reply to std::map prob on Sun, 09 Dec 2007 14:47:53 GMT]]></title><description><![CDATA[<p>das hilft mir aber nicht weiter <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1417599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1417599</guid><dc:creator><![CDATA[kiba91]]></dc:creator><pubDate>Sun, 09 Dec 2007 14:47:53 GMT</pubDate></item><item><title><![CDATA[Reply to std::map prob on Sun, 09 Dec 2007 16:18:03 GMT]]></title><description><![CDATA[<p>Wenn deine STL-Implementierung wirklich einen Default-Konstruktor braucht, dann kannst du einfach Default-Parameter angeben:</p>
<pre><code class="language-cpp">class My
{
public:
  My(int =0,int =0);
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1417664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1417664</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Sun, 09 Dec 2007 16:18:03 GMT</pubDate></item><item><title><![CDATA[Reply to std::map prob on Mon, 10 Dec 2007 06:44:32 GMT]]></title><description><![CDATA[<p>Th schrieb:</p>
<blockquote>
<p>Wenn deine STL-Implementierung wirklich einen Default-Konstruktor braucht, dann kannst du einfach Default-Parameter angeben:</p>
<pre><code class="language-cpp">class My
{
public:
  My(int =0,int =0);
};
</code></pre>
</blockquote>
<p>map&lt;&gt; an sich braucht keinen - ihr Index-Operator schon (wenn der angegebene Schlüssel noch nicht vorkommt, wird er - mit default-konstruiertem Wert - neu eingefügt). Also entweder du verpasst deiner Klasse einen Ctor, der ohne Parameter verwendet werden kann oder du verwendest den Index-Operator nicht:</p>
<pre><code class="language-cpp">void My2::set(unsigned ind, const My&amp; val)
{
  map&lt;unsigned,My&gt;::iterator pos = xyz.find(ind);
  if(pos==xyz.end())
    xyz.insert(make_pair(ind,val));
  else
    pos-&gt;second = val;
}
</code></pre>
<p>(ist etwas umfangreicher, kommt aber ohne Default-Ctor aus)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1417899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1417899</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 10 Dec 2007 06:44:32 GMT</pubDate></item></channel></rss>