<?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[Raetselhafter Fehler bei copycon (passing ... as &#x27;this&#x27; argument of ... discards qualifiers)]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>ich bin recht unerfahren, was C++ angeht - ausser kleineren Projekten hab ich noch nichts mit C++ gemacht. Das soll sich jetzt aendern. Bis gerade eben lief es auch ganz gut, aber jetzt bekomme ich einen Fehler, den ich nicht verstehe:</p>
<pre><code>util/Vector.h: In copy constructor 'Vector&lt;N, T&gt;::Vector(const Vector&lt;N, T&gt;&amp;) [with int N = 3, T = double]':
framedata/VectorFrameData.h:11:   instantiated from here
util/Vector.h:91: error: passing 'const Vector&lt;3, double&gt;' as 'this' argument of 'T Vector&lt;N, T&gt;::get(int) [with int N = 3, T = double]' discards qualifiers
util/Vector.h: In member function 'Vector&lt;N, T&gt;&amp; Vector&lt;N, T&gt;::operator=(const Vector&lt;N, T&gt;&amp;) [with int N = 3, T = double]':
framedata/VectorFrameData.h:17:   instantiated from here
util/Vector.h:115: error: passing 'const Vector&lt;3, double&gt;' as 'this' argument of 'T Vector&lt;N, T&gt;::get(int) [with int N = 3, T = double]' discards qualifiers
</code></pre>
<p>Das ganze passiert im Copy-Constructor und im ueberladenen operator=:</p>
<pre><code class="language-cpp">template&lt;int N, typename T&gt;
class Vector
{
public:
        Vector(Vector&lt;N,T&gt; const&amp; other);
--8&lt; schnipp --
        Vector&lt;N,T&gt;&amp; operator=(Vector&lt;N,T&gt; const&amp; other);
--8&lt; schnapp --
};

template&lt;int N, typename T&gt;
Vector&lt;N, T&gt;::Vector(Vector&lt;N,T&gt; const&amp; other)
{
        for (int i = 0; i &lt; N; ++i) {
                set(i, other.get(i));
        }
}

--8&lt; schnipp --

template&lt;int N, typename T&gt;
Vector&lt;N,T&gt;&amp; Vector&lt;N,T&gt;::operator=(Vector&lt;N,T&gt; const&amp; other)
{
        for (int i = 0; i &lt; N; ++i) {
                set(i, other.get(i));
        }
        return *this;
}
</code></pre>
<p>Der Fehler ist jeweils dort, wo &quot;set(i, other.get(i));&quot; steht.</p>
<p>In der Datei VectorFrameData.h steht folgendes:</p>
<pre><code class="language-cpp">VectorFrameData(Vector&lt;3,double&gt; &amp;v) : m_value(v) {}
(...)
void setData(Vector&lt;3, double&gt; &amp;v) { m_value = v; }
</code></pre>
<p>Ich hab wie gesagt keine Ahnung, wie ich das beheben kann und Google hat mir auch nicht wirklich geholfen.<br />
Was bedeuetet dieser Fehler?</p>
<p>Gruss,<br />
Matthias</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/221658/raetselhafter-fehler-bei-copycon-passing-as-this-argument-of-discards-qualifiers</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 01:32:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/221658.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Sep 2008 15:19:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Raetselhafter Fehler bei copycon (passing ... as &#x27;this&#x27; argument of ... discards qualifiers) on Mon, 01 Sep 2008 15:19:09 GMT]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>ich bin recht unerfahren, was C++ angeht - ausser kleineren Projekten hab ich noch nichts mit C++ gemacht. Das soll sich jetzt aendern. Bis gerade eben lief es auch ganz gut, aber jetzt bekomme ich einen Fehler, den ich nicht verstehe:</p>
<pre><code>util/Vector.h: In copy constructor 'Vector&lt;N, T&gt;::Vector(const Vector&lt;N, T&gt;&amp;) [with int N = 3, T = double]':
framedata/VectorFrameData.h:11:   instantiated from here
util/Vector.h:91: error: passing 'const Vector&lt;3, double&gt;' as 'this' argument of 'T Vector&lt;N, T&gt;::get(int) [with int N = 3, T = double]' discards qualifiers
util/Vector.h: In member function 'Vector&lt;N, T&gt;&amp; Vector&lt;N, T&gt;::operator=(const Vector&lt;N, T&gt;&amp;) [with int N = 3, T = double]':
framedata/VectorFrameData.h:17:   instantiated from here
util/Vector.h:115: error: passing 'const Vector&lt;3, double&gt;' as 'this' argument of 'T Vector&lt;N, T&gt;::get(int) [with int N = 3, T = double]' discards qualifiers
</code></pre>
<p>Das ganze passiert im Copy-Constructor und im ueberladenen operator=:</p>
<pre><code class="language-cpp">template&lt;int N, typename T&gt;
class Vector
{
public:
        Vector(Vector&lt;N,T&gt; const&amp; other);
--8&lt; schnipp --
        Vector&lt;N,T&gt;&amp; operator=(Vector&lt;N,T&gt; const&amp; other);
--8&lt; schnapp --
};

template&lt;int N, typename T&gt;
Vector&lt;N, T&gt;::Vector(Vector&lt;N,T&gt; const&amp; other)
{
        for (int i = 0; i &lt; N; ++i) {
                set(i, other.get(i));
        }
}

--8&lt; schnipp --

template&lt;int N, typename T&gt;
Vector&lt;N,T&gt;&amp; Vector&lt;N,T&gt;::operator=(Vector&lt;N,T&gt; const&amp; other)
{
        for (int i = 0; i &lt; N; ++i) {
                set(i, other.get(i));
        }
        return *this;
}
</code></pre>
<p>Der Fehler ist jeweils dort, wo &quot;set(i, other.get(i));&quot; steht.</p>
<p>In der Datei VectorFrameData.h steht folgendes:</p>
<pre><code class="language-cpp">VectorFrameData(Vector&lt;3,double&gt; &amp;v) : m_value(v) {}
(...)
void setData(Vector&lt;3, double&gt; &amp;v) { m_value = v; }
</code></pre>
<p>Ich hab wie gesagt keine Ahnung, wie ich das beheben kann und Google hat mir auch nicht wirklich geholfen.<br />
Was bedeuetet dieser Fehler?</p>
<p>Gruss,<br />
Matthias</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1574845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1574845</guid><dc:creator><![CDATA[Matthias__]]></dc:creator><pubDate>Mon, 01 Sep 2008 15:19:09 GMT</pubDate></item><item><title><![CDATA[Reply to Raetselhafter Fehler bei copycon (passing ... as &#x27;this&#x27; argument of ... discards qualifiers) on Mon, 01 Sep 2008 15:51:47 GMT]]></title><description><![CDATA[<p>Deine Funktion<br />
T Vector&lt;N, T&gt;::get(int)<br />
benötigt ein modifizierbares Objekt als Objektargument.<br />
In<br />
other.get(i)<br />
ist other aber nicht modifizierbar. Da get tatsächlich (logisch) keine Veränderungen am Objekt vornimmt, mithin auch auf konstante Objekte angewandt werden soll, muss es entsprechend deklariert werden:</p>
<pre><code class="language-cpp">template&lt;int N, typename T&gt;
class Vector
{
...
    T get() const;
...
</code></pre>
<p>Die Fehlermeldung</p>
<blockquote>
<p>error: passing 'const Vector&lt;3, double&gt;' as 'this' argument of 'T Vector&lt;N, T&gt;::get(int) [with int N = 3, T = double]' discards qualifiers</p>
</blockquote>
<p>ist so zu verstehen. Wenn der Compiler den Ausdruck</p>
<pre><code class="language-cpp">other.get()
</code></pre>
<p>als Aufruf der Funktion<br />
Vector&lt;N, T&gt;::get(int)<br />
auslegen würde, müsste er die const-Qualifikation des Objektarguments fallen lassen (was natürlich nicht erlaubt ist).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1574847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1574847</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 01 Sep 2008 15:51:47 GMT</pubDate></item><item><title><![CDATA[Reply to Raetselhafter Fehler bei copycon (passing ... as &#x27;this&#x27; argument of ... discards qualifiers) on Mon, 01 Sep 2008 15:55:34 GMT]]></title><description><![CDATA[<p>Hmm, haette nicht gedacht, dass die Loesung so simpel ist <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>Vielen Dank fuer die schnelle Antwort!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1574850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1574850</guid><dc:creator><![CDATA[Matthias__]]></dc:creator><pubDate>Mon, 01 Sep 2008 15:55:34 GMT</pubDate></item></channel></rss>