共用方式為


編譯器錯誤 C2676

binary 'operator' : 'type*' 未定義此運算符,或轉換成預先定義運算符可接受的類型

備註

若要使用運算子,您必須針對指定類型進行多載,或針對已定義運算子的類型定義轉換。

範例

下列範例會產生 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)
}

如果您嘗試對 this 引用類型的指標執行指標算術,也可能會發生 C2676。

指標 this 是參考型別中的型別句柄。 如需詳細資訊,請參閱指標this語意。

下列範例會產生 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();
}