有人可以向我解释为什么当我尝试从继承的对象调用基类的构造函数时出现编译器错误吗?我已经包含了我所指内容的简短示例。
Public Class Person
Public name As String
Public Sub New()
name = "John Doe"
End Sub
Public Sub New(Name As String)
name = Name
End Sub
End Class
Public Class NamedPerson
Inherits Person
Public Sub New(FirstName As String, LastName As String)
name = FirstName & " " & LastName
End Sub
'adding this makes it work
Public Sub New(Name As String)
MyBase.New(Name)
End Sub
End Class
'Valid
Dim guy1 As Person = New Person()
'Valid
Dim guy2 As Person = New Person("John Smith")
'Valid
Dim guy3 As NamedPerson = New NamedPerson("John", "Smith")
'Compiler Error
Dim guy4 As NamedPerson = New NamedPerson("John Smith")