Thread: protected internal virtual vs. protected override ??

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    71

    protected internal virtual vs. protected override ??

    my understanding is that override members must have the same access modifier as overridden members.

    In other words, if we have a member such as this one:

    Code:
    protected internal virtual Properties() {get;}
    Then in order to override it we must do this:

    Code:
    protected internal override Properties(){get;}
    But now turn your attention to the System.Configuration namespace and check out the ConfigurationElement class. It defines a protected internal virtual member named Properties but when I try to override it the compiler tells me that protected internal override is incorrect and that I must use protected override.

    Is the documentation incorrect or am I missing something?

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by y99q View Post
    my understanding is that override members must have the same access modifier as overridden members.
    That's actually why you need the change from "internal protected" to "protected".

    If I have a method in Class A in Assembly X that is protected internal, I grant permission to:
    * Any descendant of A
    * Anyone in Assembly X

    If I override this method within Assembly X, I must still make it protected internal. That much is straightforward; I keep access the same.

    If I override this method in Assembly Y, I cannot keep the "internal" modifier, because that would actually widen the scope of the original access - it would open it up to "anyone in Assembly Y" as well, which wasn't part of the original scope.

    Since I must respect the original access scope (descendants of A or members of X), and since members of Y cannot be members of X, the actual modifier that keeps access the same is "protected".

    That's actually explicitly called out in 10.6.3 of the standard.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    71
    that makes sense. thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-12-2011, 06:48 AM
  2. Protected purely virtual function
    By MarkZWEERS in forum C++ Programming
    Replies: 4
    Last Post: 08-07-2009, 01:02 PM
  3. XP Protected Folder
    By RoD in forum Tech Board
    Replies: 4
    Last Post: 11-25-2002, 05:04 AM
  4. Protected...?
    By face_master in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2001, 10:20 AM