Deutsch
Germany.ruФорумы → Архив Досок→ Программирование

Visual Studio 15 SP 1

14.07.16 20:03
Re: Visual Studio 15 SP 1
 
dymanoid постоялец
dymanoid
в ответ Murr 14.07.16 18:11

Всё элементарно.


Спецификация C# 5.0, §3.4:

all members of the base class, except instance constructors, destructors and static constructors, become members of the derived type

+ §3.5.4

Let B be a base class that declares a protected instance member M, and let D be a class that derives from B. Within the class-body of D, access to M can take one of the following forms:
• An unqualified type-name or primary-expression of the form M.
• A primary-expression of the form E.M, provided the type of E is T or a class derived from T, where T is the class type D, or a class type constructed from D
• A primary-expression of the form base.M.

In addition to these forms of access, a derived class can access a protected instance constructor of a base class in a constructor-initializer.

Расшифровывая:

- protected конструктор базового класса не наследуется (отсутствует в наследнике)

- по форме B() из D вызвать нельзя, т.к. такой член в наследнике отсутствует

- по форме E.B() вызвать тоже нельзя, потому что E может быть либо D (что не работает, ибо см. предыдущий пункт), либо наследником D, что также не работает по предыдущим 2 пунктам

- по форме base.B() вызвать тоже нельзя, потому что base.-доступ разрешается только в нестатическом конструкторе, нестатическом методе или нестатическом акцессоре (§7.6.8)

Доступ к protected конструктору базового класса доступен только в инициализаторе нестатического конструктора наследника, что выделено как отдельный пункт в §3.5.4, см выше.

 

Перейти на