I have a problem trying to generate a custom == operator for a class I've created, and cannot see what the problem is. The relevant code is in the following snippets:
Color.h:
Trim.h:
Trim.cpp:
I've tried declaring the arg to Color:perator== as "(const Color)" and as "(const Color&)" (as it is defined in Trim.h for the Trim class), with the same results, and the same problem applies where I try to compare a couple of Trims using == or != in other modules. I've seen on various web pages either argument form used, but nowhere is there a statement or explanation I've been able to find that tells which argument form is correct. The operator= works just fine.
The compiler is MSVS .NET 2002, using the SDK only (no STD, .NET or MFC).
Color.h:
Code:
class Color {
public:
Color (); // constructors
Color (COLORREF);
Color (int);
Color (COLORREF, int);
~Color (); // destructor
Color (const Color&); // Copy constructor
Color& operator= (const Color&); // operators
bool operator== (const Color);
bool operator!= (const Color);
...
Trim.h:
Code:
#include "Color.h"
class Trim {
...constructors...
bool operator== (const Trim&);
bool operator!= (const Trim&);
... other member function prototypes...
void* parent; // data members
long bspace;
Color color1, color2,
color3, color4, color5;
...
Trim.cpp:
Code:
#include "Color.h"
#include "Trim.h"
... other constructor, destructor implementations ...
bool Trim::operator!= (const Trim& a) { return !(*this == a); }
bool Trim::operator== (const Trim& a)
{
return a.color1 == color1 <----- error C2678: binary "=="; no operator found which takes a
&& a.color2 == color2 <----- left-hand operand of type 'const Color'
&& a.color3 == color3 <----- (or there is no acceptable conversion) -- repeated on each line
...
;
}
I've tried declaring the arg to Color:perator== as "(const Color)" and as "(const Color&)" (as it is defined in Trim.h for the Trim class), with the same results, and the same problem applies where I try to compare a couple of Trims using == or != in other modules. I've seen on various web pages either argument form used, but nowhere is there a statement or explanation I've been able to find that tells which argument form is correct. The operator= works just fine.
The compiler is MSVS .NET 2002, using the SDK only (no STD, .NET or MFC).