Sdílet prostřednictvím


Chyba kompilátoru C2676

binary 'operator' : 'type*' nedefinuje tento operátor ani převod na typ přijatelný pro předdefinovaný operátor.

Poznámky

Chcete-li operátor použít, je třeba jej přetížit pro daný typ nebo definovat převod na typ, pro který je operátor definován.

Příklady

Následující příklad vygeneruje C2676.

// C2676.cpp
// C2676 expected
struct C {
   C();
} c;

struct D {
   D();
   D operator >>( C& ){return * new D;}
   D operator <<( C& ){return * new D;}
} d;

struct E {
   // operator int();
};

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

K chybě C2676 může dojít také při pokusu o provedení aritmetické operace ukazatele pro ukazatel this typu odkazu.

Ukazatel this má v typu odkazu typ popisovače. Další informace naleznete v tématu Sémantika this ukazatele.

Následující příklad vygeneruje C2676.

// C2676_a.cpp
// compile with: /clr
using namespace System;

ref struct A {
   property Double default[Double] {
      Double get(Double data) {
         return data*data;
      }
   }

   A() {
      Console::WriteLine("{0}", this + 3.3);   // C2676
      Console::WriteLine("{0}", this[3.3]);   // OK
   }
};

int main() {
   A ^ mya = gcnew A();
}