<?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[cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27;]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe gerade ein VS2008 Projekt nach VS2010 konvertiert, und plötzlich bekomme ich solche Fehler.</p>
<p>Habe mal ein Minimalbeispiel erstellt und blicke irgendwie nicht dahinter, was der Compiler will. Er scheint von einem konstanten Objekt auszugehen, aber ich benutze keinen const_iterator... ?!</p>
<pre><code class="language-cpp">class TestClass
{
	int x;
public:
	TestClass(int x)
	{
		;
	}

	bool operator&lt;(const TestClass&amp; testClass) const
	{
		return x &lt; testClass.x;
	}

	void SetFunc()
	{
		x = 3;
	}
};

std::set&lt;TestClass&gt; testSet;

int main()
{
	std::set&lt;TestClass&gt;::iterator it = testSet.find(0);

	it-&gt;SetFunc(); // Error: the object has type qualifiers that are not compatible with the member function
}
</code></pre>
<p>Was ist da los?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/297551/cannot-convert-this-pointer-from-const-testclass-to-testclass-amp</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 10:19:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297551.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Jan 2012 18:36:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 18:36:13 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe gerade ein VS2008 Projekt nach VS2010 konvertiert, und plötzlich bekomme ich solche Fehler.</p>
<p>Habe mal ein Minimalbeispiel erstellt und blicke irgendwie nicht dahinter, was der Compiler will. Er scheint von einem konstanten Objekt auszugehen, aber ich benutze keinen const_iterator... ?!</p>
<pre><code class="language-cpp">class TestClass
{
	int x;
public:
	TestClass(int x)
	{
		;
	}

	bool operator&lt;(const TestClass&amp; testClass) const
	{
		return x &lt; testClass.x;
	}

	void SetFunc()
	{
		x = 3;
	}
};

std::set&lt;TestClass&gt; testSet;

int main()
{
	std::set&lt;TestClass&gt;::iterator it = testSet.find(0);

	it-&gt;SetFunc(); // Error: the object has type qualifiers that are not compatible with the member function
}
</code></pre>
<p>Was ist da los?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162681</guid><dc:creator><![CDATA[wtfvs2010]]></dc:creator><pubDate>Sun, 01 Jan 2012 18:36:13 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 18:47:18 GMT]]></title><description><![CDATA[<p>War ja klar, vorher schnell gegoogled, nix gefunden. Jetzt find ich das:</p>
<p><a href="http://blogs.msdn.com/b/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx" rel="nofollow">http://blogs.msdn.com/b/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx</a> (Problem 3: error C2662)</p>
<p>Scheint so, als wäre jetzt iterator auch ein const_iterator <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Ich komme mit den Lösungsvorschlägen nicht klar, mutable auf x funktioniert nicht, const_cast wo anwenden? Und den Rest kapier ich nicht, ich möchte keine map verwenden und möglichst wenig am Code ändern.</p>
<p>(Ich muss dazu sagen, dass x sowieso nur im Konstruktor gesetzt würde, SetFunc() ist also Blödsinn, aber auch mit y = 3 gehts nicht)</p>
<p><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/2162688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162688</guid><dc:creator><![CDATA[wtfvs2010]]></dc:creator><pubDate>Sun, 01 Jan 2012 18:47:18 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 18:55:59 GMT]]></title><description><![CDATA[<p>Wenn du den Wert so setzen könntest, wäre die Sortierung doch nicht mehr gegeben. Wenn du den Wert so setzen möchtest, ist std::set vielleicht nicht der richtige Container.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162692</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162692</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sun, 01 Jan 2012 18:55:59 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 19:09:33 GMT]]></title><description><![CDATA[<p>Ne möcht ich eh nicht. Wird, wie gesagt, eh nur im Konstruktor gesetzt. Beispiel war bisschen falsch. Aber trotzdem kommt der Fehler noch, auch wenn ich x nicht mehr verändern will.</p>
<p>Wie könnte ich den Code mit möglichst wenig Aufwand fixen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162695</guid><dc:creator><![CDATA[wtfvs2010]]></dc:creator><pubDate>Sun, 01 Jan 2012 19:09:33 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 19:27:26 GMT]]></title><description><![CDATA[<p>wtfvs2010 schrieb:</p>
<blockquote>
<p>Wie könnte ich den Code mit möglichst wenig Aufwand fixen?</p>
</blockquote>
<p>Da x die Sortierung ändert, darfst Du x eh nicht ändern.<br />
Also mußt Du ein neues Objekt anlegen mit neuem x und das in den Baum reinmachen und das alte rausmachen.<br />
Und dann hat der Compiler auch kein Problem mehr damit.</p>
<p>Willste x gar nicht ändern, reicht</p>
<pre><code class="language-cpp">void ShowFunc() const //&lt;- hier const
    { 
        cout&lt;&lt; x &lt;&lt; '\n'; 
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2162701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162701</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 01 Jan 2012 19:27:26 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 19:30:05 GMT]]></title><description><![CDATA[<p>wtfvs2010 schrieb:</p>
<blockquote>
<p>Ne möcht ich eh nicht. Wird, wie gesagt, eh nur im Konstruktor gesetzt. Beispiel war bisschen falsch. Aber trotzdem kommt der Fehler noch, auch wenn ich x nicht mehr verändern will.</p>
<p>Wie könnte ich den Code mit möglichst wenig Aufwand fixen?</p>
</blockquote>
<p>Du darfst nur const-Memberfunktionen aufrufen. Wenn du sowieso nichts ändern willst, sollte das kein Problem sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162704</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 01 Jan 2012 19:30:05 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 19:36:17 GMT]]></title><description><![CDATA[<p>Ist leider doch ein Problem. Die Klasse hat auch Methoden, die andere Member ändern. Die kann ich auch nicht aufrufen... auch wenn der Key (x) nicht angefasst wird.</p>
<p>Gibts keinen schnellen Workaround? Der Code soll einfach nur funktionieren, wie in VS2008, möchte daran echt nix großartig ändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162708</guid><dc:creator><![CDATA[wtfvs2010]]></dc:creator><pubDate>Sun, 01 Jan 2012 19:36:17 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 19:43:43 GMT]]></title><description><![CDATA[<p>wtfvs2010 schrieb:</p>
<blockquote>
<p>Ist leider doch ein Problem. Die Klasse hat auch Methoden, die andere Member ändern. Die kann ich auch nicht aufrufen... auch wenn der Key (x) nicht angefasst wird.</p>
<p>Gibts keinen schnellen Workaround? Der Code soll einfach nur funktionieren, wie in VS2008, möchte daran echt nix großartig ändern.</p>
</blockquote>
<p>Dann kannste die anderen Member mutable machen und alle nötigen Funktionen const.</p>
<p>Oder Du rufst</p>
<pre><code class="language-cpp">const_cast&lt;TestClass&gt;(*it).SetFunc();
</code></pre>
<p>auf und darfst dann halt nix aufrufen, was x verändert, sonst wäre der Baum danach verwirrt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162710</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 01 Jan 2012 19:43:43 GMT</pubDate></item><item><title><![CDATA[Reply to cannot convert &#x27;this&#x27; pointer from &#x27;const TestClass&#x27; to &#x27;TestClass &amp;amp;&#x27; on Sun, 01 Jan 2012 19:52:45 GMT]]></title><description><![CDATA[<p>Ah jo, danke. Konnte ned testen da @Steam.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162712</guid><dc:creator><![CDATA[wtfvs2010]]></dc:creator><pubDate>Sun, 01 Jan 2012 19:52:45 GMT</pubDate></item></channel></rss>