컴파일러 오류 CS1540
업데이트: 2007년 11월
오류 메시지
'type1' 형식의 한정자를 통해 보호된 'member' 멤버에 액세스할 수 없습니다. 한정자는 'type2' 형식이거나 여기서 파생된 것이어야 합니다.
Cannot access protected member 'member' via a qualifier of type 'type1'; the qualifier must be of type 'type2' (or derived from it)
파생 클래스는 자신의 기본 클래스의 보호된 멤버에 액세스할 수 있지만, 기본 클래스의 인스턴스를 통해서는 액세스할 수 없습니다.
다음 샘플에서는 CS1540 오류가 발생하는 경우를 보여 줍니다.
// CS1540.cs
public class Base
{
protected void func()
{
}
}
public class Derived : Base
{
public static void test(Base anotherInstance)
// the method declaration could be changed as follows
// public static void test(Derived anotherInstance)
{
anotherInstance.func(); // CS1540
}
}
public class Tester : Derived
{
public static void Main()
{
Base pBase = new Base();
// the allocation could be changed as follows
// Derived pBase = new Derived();
test(pBase);
}
}