boost.operators addable generiert kein a+b mit const&
-
Hallo C++'ler
ich habe (mal wieder) einen kryptischen Compile Error. Folgender Code (auf das wesentliche reduziert):
#include <boost/operators.hpp> template< typename T > struct Foo : boost::addable< Foo< T > > { explicit Foo( T x = T() ) : m_x( x ) {} Foo& operator+=( const Foo& b ) { m_x += b.m_x; return *this; } private: T m_x; }; typedef Foo< int > CFoo; void malSehn( const CFoo& a, const CFoo& b ) //void malSehn( const CFoo a, const CFoo& b ) // so würde es gehen !? { a + b; // <<-- 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; }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.
Ich benutze VC 8.0 SP1 & Security Patch und boost 1.35.0. Wo ist das Problem? Beim Compiler, im Code, bei boost.operators oder zwischen meinen Ohren?
Probiert das doch bitte mal mit einem anderen Compiler.
Gruß
Werner
-
g++, neueste Version, compiliert das bei maximalen Warnoptionen ohne Meckern.
edit: g++ schreibt man natürlich klein, auch am Satzanfang

edit2: Und boost 1.40 sollte ich noch dazu schreiben.
-
gcc-4.4.3 + boost-1.42.0 machen es hier unter Linux ohne Murren.
-
Danke Leute,
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.
Gruß
Werner