编译器错误 CS0448

更新:2007 年 11 月

错误消息

++ 或 -- 运算符的返回类型必须是包含类型或者是从包含类型派生的类型。

当您重写 ++ 或 -- 运算符时,它们必须返回与包含类型相同的类型,或者返回从包含类型派生的类型。

示例

下面的示例生成 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() {}
}