Share via


컴파일러 오류 CS0507

업데이트: 2007년 11월

오류 메시지

'function1' : 'access' 상속된 'function2' 멤버를 재정의할 때 액세스 한정자를 변경할 수 없습니다.
'function1' : cannot change access modifiers when overriding 'access' inherited member 'function2'

메서드를 재정의할 때 액세스 사양을 변경하려고 했습니다.

예제

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

// CS0507.cs
abstract public class clx
{
   virtual protected void f() {}
}

public class cly : clx
{
   public override void f() {}   // CS0507
   public static void Main() {}
}

CS0507은 참조된 메타데이터에 protected internal로 표시되어 정의된 메서드를 클래스에서 재정의하려고 하는 경우에도 발생할 수 있습니다. 이러한 경우 재정의하는 메서드를 protected로 표시해야 합니다.

// CS0507_b.cs
// compile with: /target:library
abstract public class clx
{
   virtual protected internal void f() {}
}

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

// CS0507_c.cs
// compile with: /reference:cs0507_b.dll
public class cly : clx
{
   protected internal override void f() {}   // CS0507
   // try the following line instead
   // protected override void f() {}   // OK

   public static void Main() {}
}