Generic derivance and embedded classes

N

none

Hello.
Could anybody tell me why the following code:

public abstract class Derived : Base<Derived.DerivedClass>
{
protected sealed class DerivedClass : Base<Derived.DerivedClass>.BaseClass
{
}
}

public abstract class Base<T> where T : BaseClass
{
protected abstract class BaseClass
{
}
}

gives me a <Derived.DerivedClass>.BaseClass' is inaccessible due to its
protection level(CS0122) error?

I don't get why I have a problem with protection level...
 
D

Dave Sexton

Hi,

BaseClass is a protected member of Base<T>, which means that it may only be
accessed by Base<T> itself or derived Types.

Base<Derived.DerivedClass>.BaseClass

This does not mean DerivedClass is deriving from Base<T>.
 
N

none

Dave said:
Hi,

BaseClass is a protected member of Base<T>, which means that it may only be
accessed by Base<T> itself or derived Types.

DerivedClass does not derive from Base<T> and therefore cannot access
BaseClass.
I thought, that since DerivedClass in embedded in Derived it can
automaticly access all embedded classes of Base since Derived is derived
from Base.

So I tried making the DerivedClass and BaseClass public and now I get
some other errors which I have to figure out ;)

Thanks for your clarification.
 
D

Dave Sexton

Hi,

Do you want to explain what you're trying to accomplish?

Maybe someone will be able to give you some pointers and supply working code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top