<?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[assignment of read-only location?]]></title><description><![CDATA[<p>Hi, habe ein Problem und hoffe mir kann hier jemand helfen. Habe folgende funktion geschrieben und verstehe leider die Fehlermeldung nicht.</p>
<pre><code class="language-cpp">static bool similar (set&lt;int&gt;&amp; s1, set&lt;int&gt;&amp; s2) {
   set&lt;int&gt; result;
   set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), result.begin());
   int intersection = result.size();
   set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), result.begin());
   return ((1 - (intersection / result.size())) &gt;= t_s);
}
</code></pre>
<p>Die Funktion wird auch korrekt aufgerufen.</p>
<pre><code class="language-cpp">set&lt;int&gt;* s;
...
if (similar(s[j],s[j+1]))
</code></pre>
<p>/usr/include/c++/4.0.0/bits/stl_algo.h instantiated from '_OutputIterator std::set_union(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator) [with _InputIterator1 = std::_Rb_tree_const_iterator&lt;int&gt;, _InputIterator2 = std::_Rb_tree_const_iterator&lt;int&gt;, _OutputIterator = std::_Rb_tree_const_iterator&lt;int&gt;]' Mat line 4124 1200544330468 16492<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4107 1200544330466 16486<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4112 1200544330467 16487<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4117 1200544330467 16488<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4233 1200544330466 16485<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h instantiated from '_OI std::__copy_aux(_II, _II, _OI) [with _II = std::_Rb_tree_const_iterator&lt;int&gt;, _OI = std::_Rb_tree_const_iterator&lt;int&gt;]' Mat line 317 1200544330467 16489<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h instantiated from '_OutputIterator std::copy(_InputIterator, _InputIterator, _OutputIterator) [with _InputIterator = std::_Rb_tree_const_iterator&lt;int&gt;, _OutputIterator = std::_Rb_tree_const_iterator&lt;int&gt;]' Mat line 387 1200544330468 16491<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h instantiated from 'static _OI std::__copy_normal&lt;&lt;anonymous&gt;, &lt;anonymous&gt; &gt;::copy_n(_II, _II, _OI) [with _II = std::_Rb_tree_const_iterator&lt;int&gt;, _OI = std::_Rb_tree_const_iterator&lt;int&gt;, bool &lt;anonymous&gt; = false, bool &lt;anonymous&gt; = false]' Het line 326 1200544330467 16490<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h assignment of read-only location Mat line 270 1200544330468 16493<br />
make: *** [source/hardClustering.o] Error 1 Mat line 0 1200544330469 16495</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/202944/assignment-of-read-only-location</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 04:55:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/202944.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Jan 2008 04:57:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 04:57:35 GMT]]></title><description><![CDATA[<p>Hi, habe ein Problem und hoffe mir kann hier jemand helfen. Habe folgende funktion geschrieben und verstehe leider die Fehlermeldung nicht.</p>
<pre><code class="language-cpp">static bool similar (set&lt;int&gt;&amp; s1, set&lt;int&gt;&amp; s2) {
   set&lt;int&gt; result;
   set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), result.begin());
   int intersection = result.size();
   set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), result.begin());
   return ((1 - (intersection / result.size())) &gt;= t_s);
}
</code></pre>
<p>Die Funktion wird auch korrekt aufgerufen.</p>
<pre><code class="language-cpp">set&lt;int&gt;* s;
...
if (similar(s[j],s[j+1]))
</code></pre>
<p>/usr/include/c++/4.0.0/bits/stl_algo.h instantiated from '_OutputIterator std::set_union(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator) [with _InputIterator1 = std::_Rb_tree_const_iterator&lt;int&gt;, _InputIterator2 = std::_Rb_tree_const_iterator&lt;int&gt;, _OutputIterator = std::_Rb_tree_const_iterator&lt;int&gt;]' Mat line 4124 1200544330468 16492<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4107 1200544330466 16486<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4112 1200544330467 16487<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4117 1200544330467 16488<br />
/usr/include/c++/4.0.0/bits/stl_algo.h assignment of read-only location Mat line 4233 1200544330466 16485<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h instantiated from '_OI std::__copy_aux(_II, _II, _OI) [with _II = std::_Rb_tree_const_iterator&lt;int&gt;, _OI = std::_Rb_tree_const_iterator&lt;int&gt;]' Mat line 317 1200544330467 16489<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h instantiated from '_OutputIterator std::copy(_InputIterator, _InputIterator, _OutputIterator) [with _InputIterator = std::_Rb_tree_const_iterator&lt;int&gt;, _OutputIterator = std::_Rb_tree_const_iterator&lt;int&gt;]' Mat line 387 1200544330468 16491<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h instantiated from 'static _OI std::__copy_normal&lt;&lt;anonymous&gt;, &lt;anonymous&gt; &gt;::copy_n(_II, _II, _OI) [with _II = std::_Rb_tree_const_iterator&lt;int&gt;, _OI = std::_Rb_tree_const_iterator&lt;int&gt;, bool &lt;anonymous&gt; = false, bool &lt;anonymous&gt; = false]' Het line 326 1200544330467 16490<br />
/usr/include/c++/4.0.0/bits/stl_algobase.h assignment of read-only location Mat line 270 1200544330468 16493<br />
make: *** [source/hardClustering.o] Error 1 Mat line 0 1200544330469 16495</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438095</guid><dc:creator><![CDATA[Babahm43]]></dc:creator><pubDate>Thu, 17 Jan 2008 04:57:35 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 05:59:08 GMT]]></title><description><![CDATA[<p>Was ist t_s?<br />
Wenn result.size() 0 ist schmiert dein Programm ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438107</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 17 Jan 2008 05:59:08 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 07:27:43 GMT]]></title><description><![CDATA[<p>Du kannst ein set&lt;&gt; nicht direkt als Ziel eines Algorithmus verwenden, weil es seine Schlüssel als <strong>konstante</strong> Elemente speichert. (und per STL-Algorithmus in einen leeren Container zu schreiben ist sowieso keine gute Idee)</p>
<p>Die Lösung hierfür nennt sich Insert-Iteratoren:</p>
<pre><code class="language-cpp">static bool similar (set&lt;int&gt;&amp; s1, set&lt;int&gt;&amp; s2) {
   set&lt;int&gt; result;
   set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), inserter(result,result.begin()));
   int intersection = result.size();
//   set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), result.begin());
   int union_count = s1.size()+s2.size()-intersection;//mit ein paar Kenntnissen in Mengenleere kannst du dir den union-Aufruf sparen ;)
   return ((1 - (intersection / union_count)) &gt;= t_s);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1438129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438129</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 17 Jan 2008 07:27:43 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 07:13:57 GMT]]></title><description><![CDATA[<p>int union = ... dürfte eigentlich nicht gehen. Keywords und so. :p <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>
<p>Auch hier noch das Problem das durch 0 geteilt werden kann am Ende.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438133</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 17 Jan 2008 07:13:57 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 07:27:21 GMT]]></title><description><![CDATA[<p>Fellhuhn schrieb:</p>
<blockquote>
<p>int union = ... dürfte eigentlich nicht gehen. Keywords und so. :p <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>Punkt für dich - daran hatte ich nicht gedacht.</p>
<blockquote>
<p>Auch hier noch das Problem das durch 0 geteilt werden kann am Ende.</p>
</blockquote>
<p>Ja, darauf bin ich auch nicht näher eingegangen - das muß nochmal gesondert überprüft werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438142</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 17 Jan 2008 07:27:21 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 07:30:20 GMT]]></title><description><![CDATA[<p>Kann statt union ja struct nehmen. <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="😉"
    /> <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="😃"
    /> SCNR</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438145</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 17 Jan 2008 07:30:20 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 14:32:47 GMT]]></title><description><![CDATA[<p>Meine Mengen sind nichtleer, daher ist Division durch null ausgeschlossen und t_s ist ein Grenzwert &gt; 0.<br />
Aber danke fuer den Tip mit dem inserter und die Nachhilfe in Mengenlehre (haett ich eigentlich wissen muessen)<br />
Hat geholfen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438445</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438445</guid><dc:creator><![CDATA[Babahm43]]></dc:creator><pubDate>Thu, 17 Jan 2008 14:32:47 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 14:49:11 GMT]]></title><description><![CDATA[<p>Babahm43 schrieb:</p>
<blockquote>
<p>Meine Mengen sind nichtleer, daher ist Division durch null ausgeschlossen und t_s ist ein Grenzwert &gt; 0.</p>
</blockquote>
<p>Und wie stellst du das sicher? Die Funktion dort weiß nicht, ob die übergebenen Mengen leer sind - und überprüft es auch nicht.</p>
<p>PS: Was mir im Nachhinein aufgefallen ist: Du rechnest mit Ganzzahl-Arithmetik - und da wird die Division &quot;intersection/union_count&quot; nur dann einen Wert ungleich 0 liefern, wenn deine Mengen identisch sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438463</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 17 Jan 2008 14:49:11 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 15:42:47 GMT]]></title><description><![CDATA[<p>Das ergibt sich aus dem restl. Programm und wie die Mengen erstellt werden. Ein zusaetzlicher check waere wahrscheinlich trotzdem nicht unangebracht.<br />
Mit der Ganzzahlarithmetik hast du vollkommen recht, dumm von mir. Koennt ich ja direkt schreiben return true. <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/1438509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438509</guid><dc:creator><![CDATA[Babahm43]]></dc:creator><pubDate>Thu, 17 Jan 2008 15:42:47 GMT</pubDate></item><item><title><![CDATA[Reply to assignment of read-only location? on Thu, 17 Jan 2008 15:50:45 GMT]]></title><description><![CDATA[<p>Babahm43 schrieb:</p>
<blockquote>
<p>Koennt ich ja direkt schreiben return true. <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>Ja, könntest du vermutlich (wenn t_s kleiner als 1 ist, wäre aber &quot;return s1!=s2;&quot; korrekter). Aber da ich nicht vermute, daß du damit dein Problem richtig modelliert hast - wechsle lieber auf Gleitkomma-Arithmetik, dann macht die Division auch wieder Sinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1438515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1438515</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 17 Jan 2008 15:50:45 GMT</pubDate></item></channel></rss>