Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating base class with Sub New(with parameters)
Message
 
À
01/10/2004 11:19:29
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00947856
Message ID:
00947980
Vues:
17
VB supports both Constructors and Overloading



>Doesn't VB support overloaded methods? (I don't know, I use C#) ... you'd need two constructors for your class. One with no parameters and then one with the parameters you need. If VB doesn't support this construct, then someone who knows VB better than I needs to help out here, because I'm sure there's a way to handle this properly. Sorry. =(
>
>~~Bonnie
>
>
>
>>Bonnie,
>>
>>I'm afraid you're wrong on this one. I still won't be able issue:
>>
Dim oClass As MyChildClass = New MyChildClass(MyCaller)
>>Instead, I will get an error saying something like "too many parameters for Sub New()".
>>
>>>Danijel,
>>>
>>>>>Is there a way to get this done without having to declare Sub New in each of the derived classes?
>>>
>>>Yeah, just stick a Sub New with no parameters in the MyParentClass. It won't do anything, but you have to have it.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>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
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform