Export (0) Print
Expand All
Expand Minimize

Compiler Error C2676

binary 'operator' : 'type' does not define this operator or a conversion to a type acceptable to the predefined operator

To use the operator, you must overload it for the specified type or define a conversion to a type for which the operator is defined.

The following sample generates C2676:

// C2676a.cpp
class C
{
   public:
   C();
} c;

class D
{
   public:
   D();
   // D operator >>( C& );
   D operator <<( C& );
} d;

class E
{
public:
   // operator int();
};

int main()
{
   d >> c;   // C2676 uncomment operator >> in class D to resolve
   d << c;   // OK, operator << defined
   E e1, e2;
   e1 == e2;   // C2676 uncomment opeator int in class E
               // then, it is OK even though neither E::operator==(E) nor 
               // operator==(E, E) is defined. Uses the conversion to int 
               // and then the builtin-operator==(int, int)
}
Show:
© 2014 Microsoft