Share via


컴파일러 오류 CS0448

업데이트: 2007년 11월

오류 메시지

++ 또는 -- 연산자의 반환 형식은 포함하는 형식이거나 포함하는 형식에서 파생되어야 합니다.
The return type for ++ or -- operator must be the containing type or derived from the containing type

++ 또는 -- 연산자를 재정의하는 경우 포함하는 형식과 동일한 형식을 반환하거나 포함하는 형식에서 파생된 형식을 반환해야 합니다.

예제

다음 샘플에서는 CS0448 오류가 발생하는 경우를 보여 줍니다.

// CS0448.cs
class C5
{
   public static int operator ++(C5 c) { return null; }   // CS0448
   public static C5 operator --(C5 c) { return null; }   // OK
   public static void Main() {}
}

다음 샘플에서는 CS0448 오류가 발생하는 경우를 보여 줍니다.

// CS0448_b.cs
public struct S
{
   public static S? operator ++(S s) { return new S(); }   // CS0448
   public static S? operator --(S s) { return new S(); }   // CS0448
}

public struct T
{
// OK
   public static T operator --(T t) { return new T(); }
   public static T operator ++(T t) { return new T(); }

   public static T? operator --(T? t) { return new T(); }
   public static T? operator ++(T? t) { return new T(); }

   public static void Main() {}
}