Поделиться через


Ошибка компилятора CS0448

Обновлен: Ноябрь 2007

Сообщение об ошибке

Возвращаемый тип оператора ++ или -- должен быть вмещающего типа или типа, производного от вмещающего типа
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() {}
}