kmrneedsnethelp <kmrneedsneth
@discussions.microsoft.com> wrote:
> I have the class structure shown below. When I compile I receive the
> following erros:
> 'B.B()' is inaccessible due to its protection level
> 'C.C()' is inaccessible due to its protection level
> I am sure it is because of the protected keyword on the constructors for B
> and C but I do not understand the underlying reason.
> Can anyone explain it?
be called from classes *derived* from them. A doesn't derive from B or
C, therefore it can't call protected members of B or C.
On Wed, 06 Jun 2007 10:46:00 -0700, kmrneedsnethelp
<kmrneedsneth
@discussions.microsoft.com> wrote:
> I have the class structure shown below. When I compile I receive the
> following erros:
> 'B.B()' is inaccessible due to its protection level
> 'C.C()' is inaccessible due to its protection level
> I am sure it is because of the protected keyword on the constructors for
> B
> and C but I do not understand the underlying reason.
> Can anyone explain it?
You may want to read this:
http://msdn2.microsoft.com/en-us/library/wxh6fsc7.aspx As for your specific question, the "protected" access modifier allows
derived classes to access base class members, but it doesn't work the
other way. In your example, you're trying to access protected members in
the derived classes, from the base class. The members need to be public
for A to access the constructors.
Pete
-----------------------------------------------Reply-----------------------------------------------
On Wed, 06 Jun 2007 10:46:00 -0700, kmrneedsnethelp
<kmrneedsneth
@discussions.microsoft.com> wrote:
> [...]
> I am sure it is because of the protected keyword on the constructors for
> B
> and C but I do not understand the underlying reason.
By the way, you can probably accomplish the general idea of what you're
trying to do by using the "internal" access modifier. This will allow A
to access B and C constructors (assuming they remain in the same assembly)
while hiding them from other code that may use the classes.
Pete