Condividi tramite


Errore del compilatore C2676

binary 'operator': 'type*' non definisce questo operatore o una conversione in un tipo accettabile per l'operatore predefinito

Osservazioni:

Per usare l'operatore, è necessario eseguirne l'overload per il tipo specificato o definire una conversione in un tipo per cui l'operatore è definito.

Esempi

L'esempio seguente genera l'errore 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)
}

C2676 può verificarsi anche se si tenta di eseguire l'aritmetica del puntatore sul this puntatore di un tipo riferimento.

Il this puntatore è di tipo handle in un tipo riferimento. Per altre informazioni, vedere Semantica del this puntatore.

L'esempio seguente genera l'errore 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();
}