none
Problem with inheriting RRS feed

  • Question

  • Hi, I keep getting the following error message:

     

    Error    1    Cannot access protected member 'DirSync.FileSystemEntry.Parent' via a qualifier of type 'DirSync.FileEntry'; the qualifier must be of type 'DirSync.DirEntry' (or derived from it)    D:\Programming\VS\Apps\DirSync\DirSync\DirEntry.cs    58    77    DirSync

     

    Both DirEntry and FileEntry and derived from FileSystemEntry and have both inherited the Parent property from it. Why will it not let me access it from the FileEntry class?

    Saturday, July 9, 2011 6:40 PM

Answers

  • Are you trying to access a DirEntry.Parent from inside FileEntry, or other way around? That is not possible.

    I believe it has already been mentioned that you can add a new public member to both DirEntry and FileEntry that wraps FileSystemEntry protected Parent member.

    • Marked as answer by Danzence Friday, July 15, 2011 3:36 PM
    Thursday, July 14, 2011 2:45 PM
    Moderator
  • By design.  Protected members are accessible by classes that inherit them directly, but it is their OWN members, not members of other classes that have the same root.
    MCP
    • Marked as answer by Danzence Friday, July 15, 2011 3:36 PM
    Thursday, July 14, 2011 4:53 PM

All replies

  • Check out the answers in this link : http://stackoverflow.com/questions/567705/why-cant-i-access-c-protected-members-except-like-this
    Please mark this as answer or vote as helpful if it solved your problem
    Monday, July 11, 2011 4:19 AM
  • If GregHenry link doesn't help you may want to post little bit code to show the derived classes and how the failing method call is made.
    Monday, July 11, 2011 2:16 PM
    Moderator
  • From the error message, I take it that you hold a member object inside DirEntry that is of type FileEntry, and you want to acess Parent in the contained FileEntry object from DirEntry's code.  That cannot be done.  Even though they both have the same class root, it doesn't mean you can access protected members of an otherwise unrelated class.  Make Parent public.
    MCP
    Monday, July 11, 2011 2:52 PM
  • The property I am trying to access is part of the parent of both classes, so I am unsure why it is denying me access?

     

    class FileSystemEntry // has protected "Parent" property.

    class DirEntry : FileSystemEntry

    class FileEntry : FileSystemEntry

     

    Why can these two not both access Parent from within each other?

    Thursday, July 14, 2011 2:30 PM
  • Are you trying to access a DirEntry.Parent from inside FileEntry, or other way around? That is not possible.

    I believe it has already been mentioned that you can add a new public member to both DirEntry and FileEntry that wraps FileSystemEntry protected Parent member.

    • Marked as answer by Danzence Friday, July 15, 2011 3:36 PM
    Thursday, July 14, 2011 2:45 PM
    Moderator
  • Is that a bug or by design?
    Thursday, July 14, 2011 2:57 PM
  • By design.  Protected members are accessible by classes that inherit them directly, but it is their OWN members, not members of other classes that have the same root.
    MCP
    • Marked as answer by Danzence Friday, July 15, 2011 3:36 PM
    Thursday, July 14, 2011 4:53 PM
  • I see. Thanks :)
    Friday, July 15, 2011 3:36 PM