Struct Inheritance

In Mercury, Structures can specify an ancestor, allowing a newly declared struct to inherit the fields and methods of its base struct. Unlike classes, structs are not polymorphic, and members cannot be virtual or overriden.

Public Structure MyStruct1

    Public Dim a As Integer
    
    Public Sub DoSomething() 
        ..
    End Sub
    
End Structure

Public Structure MyStruct2
    Inherits MyStruct1

    Public Dim B As String
    
    Public Sub DoSomethingElse() 
        ..
    End Sub
    
End Structure

In the example above, MyStruct2 contains all the fields and methods of MyStruct1, as well as those defined for MyStruct2 itself.

See Also