Why this compile error? (inheritance)


A

Armin Zingler

Hi folks,

sending a sign of life here....:


MustInherit Class Base(Of T)
Protected Class Inner
End Class

Protected MustOverride Function func(ByVal par As T) As Inner

End Class

Class Inherited
Inherits Base(Of Integer)

Protected Overrides Function func(ByVal par As Integer) As Base(Of Integer).Inner '<<<<<< ERROR
End Function
End Class


The error message at the declaration of Function 'func' in class 'Inherited' says:

'Base(Of T).Inner' is not accessible in this context because it is 'Protected'

Right, the Class "Inner" is Protected. But the code is in a derived class,
and function 'func' is also protected. Therefore it should work, so why the
error? Note that the declaration is created automatically by pressing the
Enter key at the end of the "Inherits" line.
 
Ad

Advertisements

J

Jason Keats

Armin said:
Hi folks,

sending a sign of life here....:


MustInherit Class Base(Of T)
Protected Class Inner
End Class

Protected MustOverride Function func(ByVal par As T) As Inner

End Class

Class Inherited
Inherits Base(Of Integer)

Protected Overrides Function func(ByVal par As Integer) As Base(Of Integer).Inner '<<<<<< ERROR
End Function
End Class


The error message at the declaration of Function 'func' in class 'Inherited' says:

'Base(Of T).Inner' is not accessible in this context because it is 'Protected'

Right, the Class "Inner" is Protected. But the code is in a derived class,
and function 'func' is also protected. Therefore it should work, so why the
error? Note that the declaration is created automatically by pressing the
Enter key at the end of the "Inherits" line.

I'd try using:
Protected Friend Class Inner
End Class

HTH
 
Ad

Advertisements

A

Armin Zingler

Am 15.03.2011 12:57, schrieb Jason Keats:
I'd try using:
Protected Friend Class Inner
End Class

HTH

But I want it to be "Protected Class Inner". The nested class
must only be visible to derived classes, not to all classes
in the assembly.

.....

I figured it out: It works If I change it to

Protected Overrides Function func(ByVal par As Integer) As Inner

Strange.

Thanks anyway!
 

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