Why this compile error? (inheritance)

  • Thread starter Thread starter Armin Zingler
  • Start date Start date
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.
 
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
 
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!
 
Back
Top