<?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[boost.operators addable generiert kein a+b mit const&amp;amp;]]></title><description><![CDATA[<p>Hallo C++'ler</p>
<p>ich habe (mal wieder) einen kryptischen Compile Error. Folgender Code (auf das wesentliche reduziert):</p>
<pre><code class="language-cpp">#include &lt;boost/operators.hpp&gt;

template&lt; typename T &gt;
struct Foo : boost::addable&lt; Foo&lt; T &gt; &gt;
{
    explicit Foo( T x = T() ) : m_x( x ) {}

    Foo&amp; operator+=( const Foo&amp; b )
    {
        m_x += b.m_x;
        return *this;
    }
private:
    T  m_x;
};

typedef Foo&lt; int &gt;   CFoo;

void   malSehn( const CFoo&amp; a, const CFoo&amp; b )
//void malSehn( const CFoo a, const CFoo&amp; b ) // so würde es gehen !?
{
    a + b;  // &lt;&lt;-- compile error: error C2676: binary '+' : 'const CFoo' does not define this operator or a conversion to a type acceptable to the predefined operator
}

int main()
{
    CFoo a(-2), b(9);
    malSehn( a, b );
    return 0;
}
</code></pre>
<p>In Zeile 23 kommt es dann zum besagten Compile Error. Angeblich findet der Compiler keine akzeptable Konvertierung. Es würde aber auch funktionieren, wenn Foo kein Template wäre.</p>
<p>Ich benutze VC 8.0 SP1 &amp; Security Patch und boost 1.35.0. Wo ist das Problem? Beim Compiler, im Code, bei boost.operators oder zwischen meinen Ohren?</p>
<p>Probiert das doch bitte mal mit einem anderen Compiler.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274907/boost-operators-addable-generiert-kein-a-b-mit-const-amp</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 07:55:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274907.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Oct 2010 10:48:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost.operators addable generiert kein a+b mit const&amp;amp; on Tue, 05 Oct 2010 10:48:22 GMT]]></title><description><![CDATA[<p>Hallo C++'ler</p>
<p>ich habe (mal wieder) einen kryptischen Compile Error. Folgender Code (auf das wesentliche reduziert):</p>
<pre><code class="language-cpp">#include &lt;boost/operators.hpp&gt;

template&lt; typename T &gt;
struct Foo : boost::addable&lt; Foo&lt; T &gt; &gt;
{
    explicit Foo( T x = T() ) : m_x( x ) {}

    Foo&amp; operator+=( const Foo&amp; b )
    {
        m_x += b.m_x;
        return *this;
    }
private:
    T  m_x;
};

typedef Foo&lt; int &gt;   CFoo;

void   malSehn( const CFoo&amp; a, const CFoo&amp; b )
//void malSehn( const CFoo a, const CFoo&amp; b ) // so würde es gehen !?
{
    a + b;  // &lt;&lt;-- compile error: error C2676: binary '+' : 'const CFoo' does not define this operator or a conversion to a type acceptable to the predefined operator
}

int main()
{
    CFoo a(-2), b(9);
    malSehn( a, b );
    return 0;
}
</code></pre>
<p>In Zeile 23 kommt es dann zum besagten Compile Error. Angeblich findet der Compiler keine akzeptable Konvertierung. Es würde aber auch funktionieren, wenn Foo kein Template wäre.</p>
<p>Ich benutze VC 8.0 SP1 &amp; Security Patch und boost 1.35.0. Wo ist das Problem? Beim Compiler, im Code, bei boost.operators oder zwischen meinen Ohren?</p>
<p>Probiert das doch bitte mal mit einem anderen Compiler.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961577</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961577</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 05 Oct 2010 10:48:22 GMT</pubDate></item><item><title><![CDATA[Reply to boost.operators addable generiert kein a+b mit const&amp;amp; on Tue, 05 Oct 2010 11:12:58 GMT]]></title><description><![CDATA[<p>g++, neueste Version, compiliert das bei maximalen Warnoptionen ohne Meckern.</p>
<p>edit: g++ schreibt man natürlich klein, auch am Satzanfang <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="😃"
    /><br />
edit2: Und boost 1.40 sollte ich noch dazu schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961580</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 Oct 2010 11:12:58 GMT</pubDate></item><item><title><![CDATA[Reply to boost.operators addable generiert kein a+b mit const&amp;amp; on Tue, 05 Oct 2010 11:01:30 GMT]]></title><description><![CDATA[<p>gcc-4.4.3 + boost-1.42.0 machen es hier unter Linux ohne Murren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961584</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Tue, 05 Oct 2010 11:01:30 GMT</pubDate></item><item><title><![CDATA[Reply to boost.operators addable generiert kein a+b mit const&amp;amp; on Tue, 05 Oct 2010 11:31:38 GMT]]></title><description><![CDATA[<p>Danke Leute,</p>
<p>an boost liegt es nicht, ich habe das gleiche Problem auch mit boost.1.44 und mit VS 2010 geht der Fehler auch nicht weg. Dann darf man wohl auf eine Microsoft-Krankheit schließen.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961593</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 05 Oct 2010 11:31:38 GMT</pubDate></item></channel></rss>