Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating base class with Sub New(with parameters)
Message
De
01/10/2004 06:28:59
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Creating base class with Sub New(with parameters)
Divers
Thread ID:
00947856
Message ID:
00947856
Vues:
115
Ok, so I have this class that I want some other classes to inherit from.
Public MustInherit Class MyParentClass
    Protected WithEvents _Caller As MyBaseClass

    Public Sub New(ByVal oObj As MyBaseClass)
        If Not oObj Is Nothing Then
            _Caller = oObj
        End If
    End Sub
End Class
Then, there is a class that derives from the parent:
Public Class MyChildClass
    Inherits MyParentClass
    Public Sub run(ByVal parms As Object)
        Dim str As String
        ...
    End Sub
End Class
And the call in code would ideally look something like this
Dim oClass As MyChildClass = New MyChildClass(MyCaller)
As you can see, I want the Sub New() of derived class objects to take a caller object as a parameter in order to set a reference to it. However, this isn't working that easy as I am getting a message:

'MyChildClass' must declare a 'Sub New()' because its base class 'MyParentClass' does not have an accessible 'Sub New' that can be called with no arguments.'

Is there a way to get this done without having to declare Sub New in each of the derived classes?

Thanks
Danijel
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform