Show/Hide Toolbars

XSharp

Cannot access protected member 'member' via a qualifier of type 'type1'; the qualifier must be of type 'type2' (or derived from it)

 

A derived class cannot access protected members of its base class through an instance of the base class. An instance of the base class declared in the derived class might, at run time, be an instance of another type that is derived from the same base but is not otherwise related to the derived class. Because protected members can be accessed only by derived types, any attempts to access protected members that might not be valid at run time are marked by the compiler as not valid.

 

In the Employee class in the following example, emp2 and emp3 both have type Person at compile time, but emp2 has type Manager at run time. Because Employee is not derived from Manager, it cannot access the protected members of the base class, Person, through an instance of the Manager class. The compiler cannot determine what the run-time type of the two Person objects will be. Therefore, both the call from emp2 and the call from emp3 cause compiler error XS1540.

 

 

// XS1540.PRG