boost::operators?
-
Hallo,
ich habe eine klasse A, welche bestimmte Operatoren für eine andere template-Klasse definiert.
class A { template<class C> friend bool operator==<>(const A& a,const B<C>& B); //... }; template<class C> bool operator==<>(const A& a,const B<C>& B) { //... }Wie muss ich nun von boost::operators btw. in diesem konkreten Fall von boost::equality_comparable ableiten, damit != und der andere ==-Operator für jedes B<Klasse> definiert wird?
-
Mit einem Template wird das wohl gar nicht gehen. Bleibt nur noch die Lösung es selbst nochmal hinzuschreiben. Also
template< typename C > class B { // ... }; class A // : public boost::equality_comparable< A, template? B<> > { public: template< typename C > bool operator==( const B< C >& b ) const { return // true, wenn's gleich ist; } }; // -- statt boost::equality_comparable< A, B<> > template< typename C > bool operator==(const B< C >& b, const A& a) { return a == b; } template< typename C > bool operator!=(const B< C >& b, const A& a) { return !(a == b); } template< typename C > bool operator!=(const A& a, const B< C >& b) { return !(a == b); }Gruß
Werner
-
Was spricht dagegen, das ganze im Template B zu implementieren? Dann kannst du auch Boost.Operators benutzen.