다음을 통해 공유


컴파일러 오류 C2676

이진 '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)
}

참조 형식의 포인터에 대한 포인터 산술 연산을 수행하려는 경우에도 C2676이 this 발생할 수 있습니다.

포인터는 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();
}