why not inherit from type 'b(Of a)'

×

דני

Public Class Form1
Public Class a

End Class
Public Class a1
Inherits a
End Class
Public Class a2
Inherits a
Private dsfs As d(Of c2) 'err Error 1 Type argument 'c2' does
not inherit from or implement the constraint type 'b(Of a)'.

End Class
Public Class b(Of T As a)

End Class

Public Class c
Inherits b(Of a)

End Class
Public Class c1
Inherits b(Of a)

End Class
Public Class c2
Inherits b(Of a1)

End Class
Public Class c3
Inherits b(Of a2)

End Class
Public Class d(Of T As b(Of a))

End Class
Dim r As New d(Of c3) 'err Error 1 Type argument 'c2' does not
inherit from or implement the constraint type 'b(Of a)'.

Dim r1 As New d(Of c) 'ok

End Class
 
F

Family Tree Mike

דני said:
Public Class Form1
Public Class a

End Class
Public Class a1
Inherits a
End Class
Public Class a2
Inherits a
Private dsfs As d(Of c2) 'err Error 1 Type argument 'c2' does
not inherit from or implement the constraint type 'b(Of a)'.

End Class
Public Class b(Of T As a)

End Class

Public Class c
Inherits b(Of a)

End Class
Public Class c1
Inherits b(Of a)

End Class
Public Class c2
Inherits b(Of a1)

End Class
Public Class c3
Inherits b(Of a2)

End Class
Public Class d(Of T As b(Of a))

End Class
Dim r As New d(Of c3) 'err Error 1 Type argument 'c2' does not
inherit from or implement the constraint type 'b(Of a)'.

Dim r1 As New d(Of c) 'ok

End Class


Converting this to something real world:

Public Class Animal ' was class a
End Class

Public Class Mammal ' was class a1
Inherits Animal
End Class

Public Class Reptile ' was class a2
Inherits Animal
Private dsfs As ZooAssociation(Of SmallMammalZoo) ' fails
Private dsfsCorrect As ZooAssociation(Of Zoo(Of Animal)) ' works
End Class

Public Class Zoo(Of T As Animal) ' was class b(of a)
End Class

Public Class PettingZoo ' was class c
Inherits Zoo(Of Animal)
End Class

Public Class Farm ' was class c1
Inherits Zoo(Of Animal)
End Class

Public Class SmallMammalZoo ' was class c2
Inherits Zoo(Of Mammal)
End Class

Public Class ReptileZoo ' was class c3
Inherits Zoo(Of Reptile)
End Class

Public Class ZooAssociation(Of T As Zoo(Of Animal)) ' was class d
End Class

Module Module1
Sub Main()
Dim r As New ZooAssociation(Of ReptileZoo) ' fails
Dim rCorrect As New ZooAssociation(Of Zoo(Of Animal)) ' works
End Sub
End Module


In both cases, you are trying to use a restrictive zoo (SmallMammalZoo and
ReptileZoo), where Zoo(of Animal) is required. A Zoo(of Animal) can contain
both SmallMammal objects and Reptile objects. Since a ZooAssociation object
can have a more generic Zoo added to it, you would have problems reading
through it when you stumbled onto an Octopus :)

I hope this helps.
 
F

Family Tree Mike

דני said:
Public Class Form1
Public Class a

End Class
Public Class a1
Inherits a
End Class
Public Class a2
Inherits a
Private dsfs As d(Of c2) 'err Error 1 Type argument 'c2' does
not inherit from or implement the constraint type 'b(Of a)'.

End Class
Public Class b(Of T As a)

End Class

Public Class c
Inherits b(Of a)

End Class
Public Class c1
Inherits b(Of a)

End Class
Public Class c2
Inherits b(Of a1)

End Class
Public Class c3
Inherits b(Of a2)

End Class
Public Class d(Of T As b(Of a))

End Class
Dim r As New d(Of c3) 'err Error 1 Type argument 'c2' does not
inherit from or implement the constraint type 'b(Of a)'.

Dim r1 As New d(Of c) 'ok

End Class


Converting this to something real world:

Public Class Animal ' was class a
End Class

Public Class Mammal ' was class a1
Inherits Animal
End Class

Public Class Reptile ' was class a2
Inherits Animal
Private dsfs As ZooAssociation(Of SmallMammalZoo) ' fails
Private dsfsCorrect As ZooAssociation(Of Zoo(Of Animal)) ' works
End Class

Public Class Zoo(Of T As Animal) ' was class b(of a)
End Class

Public Class PettingZoo ' was class c
Inherits Zoo(Of Animal)
End Class

Public Class Farm ' was class c1
Inherits Zoo(Of Animal)
End Class

Public Class SmallMammalZoo ' was class c2
Inherits Zoo(Of Mammal)
End Class

Public Class ReptileZoo ' was class c3
Inherits Zoo(Of Reptile)
End Class

Public Class ZooAssociation(Of T As Zoo(Of Animal)) ' was class d
End Class

Module Module1
Sub Main()
Dim r As New ZooAssociation(Of ReptileZoo) ' fails
Dim rCorrect As New ZooAssociation(Of Zoo(Of Animal)) ' works
End Sub
End Module


In both cases, you are trying to use a restrictive zoo (SmallMammalZoo and
ReptileZoo), where Zoo(of Animal) is required. A Zoo(of Animal) can contain
both SmallMammal objects and Reptile objects. Since a ZooAssociation object
can have a more generic Zoo added to it, you would have problems reading
through it when you stumbled onto an Octopus :)

I hope this helps.
 
×

דני

thanke ypu for your answer.
i want to creat a class that get zoo animel and work with animel properties
such as name or coloul of the animel. how can i do it?
Public Class Animal ' was class a

End Class

Public Class Mammal ' was class a1
Inherits Animal
End Class

Public Class Reptile ' was class a2
Inherits Animal
Private dsfs As ZooAssociation(Of SmallMammalZoo) ' fails
Private dsfsCorrect As ZooAssociation(Of Zoo(Of Animal)) ' works
End Class

Public Class Zoo(Of T As Animal) ' was class b(of a)
End Class

Public Class PettingZoo ' was class c
Inherits Zoo(Of Animal)
End Class

Public Class Farm ' was class c1
Inherits Zoo(Of Animal)
End Class

Public Class SmallMammalZoo ' was class c2
Inherits Zoo(Of Mammal)
End Class

Public Class ReptileZoo ' was class c3
Inherits Zoo(Of Reptile)
End Class
Public Class ZooAssociation(Of T As Zoo(Of Animal)) ' was class d
End Class

Module Module1
Sub Main()
Dim r As New ZooAssociation(Of ReptileZoo) ' fails
Dim rCorrect As New ZooAssociation(Of Zoo(Of Animal)) ' works
End Sub
End Module
 
×

דני

thanke ypu for your answer.
i want to creat a class that get zoo animel and work with animel properties
such as name or coloul of the animel. how can i do it?
Public Class Animal ' was class a

End Class

Public Class Mammal ' was class a1
Inherits Animal
End Class

Public Class Reptile ' was class a2
Inherits Animal
Private dsfs As ZooAssociation(Of SmallMammalZoo) ' fails
Private dsfsCorrect As ZooAssociation(Of Zoo(Of Animal)) ' works
End Class

Public Class Zoo(Of T As Animal) ' was class b(of a)
End Class

Public Class PettingZoo ' was class c
Inherits Zoo(Of Animal)
End Class

Public Class Farm ' was class c1
Inherits Zoo(Of Animal)
End Class

Public Class SmallMammalZoo ' was class c2
Inherits Zoo(Of Mammal)
End Class

Public Class ReptileZoo ' was class c3
Inherits Zoo(Of Reptile)
End Class
Public Class ZooAssociation(Of T As Zoo(Of Animal)) ' was class d
End Class

Module Module1
Sub Main()
Dim r As New ZooAssociation(Of ReptileZoo) ' fails
Dim rCorrect As New ZooAssociation(Of Zoo(Of Animal)) ' works
End Sub
End Module
 
F

Family Tree Mike

דני said:
thanke ypu for your answer.
i want to creat a class that get zoo animel and work with animel properties
such as name or coloul of the animel. how can i do it?

It would seem that:

dim MyPets = new List(of Animal)

would be sufficient. I have a feeling that something is beling lost in
translation somewhere.

Mike
 
F

Family Tree Mike

דני said:
thanke ypu for your answer.
i want to creat a class that get zoo animel and work with animel properties
such as name or coloul of the animel. how can i do it?

It would seem that:

dim MyPets = new List(of Animal)

would be sufficient. I have a feeling that something is beling lost in
translation somewhere.

Mike
 

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