<?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::set custom key class]]></title><description><![CDATA[<p>Hallo!<br />
Ich möchte eine eigene Klasse als Key für Sets und Maps verwenden.<br />
Die Klasse sieht z.b. so aus:</p>
<pre><code class="language-cpp">class foo 
{
 public:
  foo(string a, string b) {this-&gt;a = a; this-&gt;b = b};
  string a;
  string b;

  bool operator==(const foo&amp; ref) const { a.compare(ref.a) == 0; };
  bool operator&lt;(const foo&amp; ref) const ( a.compare(ref.x) &lt; 0;};
}
</code></pre>
<p>und jetzt ein set:</p>
<pre><code class="language-cpp">set&lt;foo&gt; s;
s.insert(foo(&quot;x&quot;,&quot;y&quot;));
</code></pre>
<p>und jetzt möchte ich nach einem Key suchen:</p>
<pre><code class="language-cpp">// Version 1
s.find(foo(&quot;x&quot;,&quot;y&quot;));

// Version 2
s.find(foo(&quot;x&quot;,&quot;&quot;));
</code></pre>
<p>Also Version 1 findet den entsprechenden Eintrag im Set, Version 2 jedoch nicht. Wie muss man den Code umändern, damit auch Version 2 den entsprechenden Eintrag findet?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/233446/std-set-custom-key-class</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 21:59:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/233446.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Feb 2009 18:54:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::set custom key class on Wed, 04 Feb 2009 18:54:41 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Ich möchte eine eigene Klasse als Key für Sets und Maps verwenden.<br />
Die Klasse sieht z.b. so aus:</p>
<pre><code class="language-cpp">class foo 
{
 public:
  foo(string a, string b) {this-&gt;a = a; this-&gt;b = b};
  string a;
  string b;

  bool operator==(const foo&amp; ref) const { a.compare(ref.a) == 0; };
  bool operator&lt;(const foo&amp; ref) const ( a.compare(ref.x) &lt; 0;};
}
</code></pre>
<p>und jetzt ein set:</p>
<pre><code class="language-cpp">set&lt;foo&gt; s;
s.insert(foo(&quot;x&quot;,&quot;y&quot;));
</code></pre>
<p>und jetzt möchte ich nach einem Key suchen:</p>
<pre><code class="language-cpp">// Version 1
s.find(foo(&quot;x&quot;,&quot;y&quot;));

// Version 2
s.find(foo(&quot;x&quot;,&quot;&quot;));
</code></pre>
<p>Also Version 1 findet den entsprechenden Eintrag im Set, Version 2 jedoch nicht. Wie muss man den Code umändern, damit auch Version 2 den entsprechenden Eintrag findet?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1658085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1658085</guid><dc:creator><![CDATA[pixsta]]></dc:creator><pubDate>Wed, 04 Feb 2009 18:54:41 GMT</pubDate></item><item><title><![CDATA[Reply to std::set custom key class on Wed, 04 Feb 2009 19:15:10 GMT]]></title><description><![CDATA[<p>ok, ich habe jetzt eine Lösung gefunden:</p>
<pre><code class="language-cpp">foo: operator ();

std::find(...);
</code></pre>
<p>Wäre aber trotzdem interessant, ob es eine andere Möglichkeit gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1658099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1658099</guid><dc:creator><![CDATA[pixsta]]></dc:creator><pubDate>Wed, 04 Feb 2009 19:15:10 GMT</pubDate></item><item><title><![CDATA[Reply to std::set custom key class on Wed, 04 Feb 2009 19:41:05 GMT]]></title><description><![CDATA[<p>Poste mal Code der sich auch compilieren lässt, vielleicht hilft dir dann jemand.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1658110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1658110</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 04 Feb 2009 19:41:05 GMT</pubDate></item></channel></rss>