Home > database >  Inheirting class not seeing base class
Inheirting class not seeing base class

Time:10-05

I have an abstract class in one file:

namespace Dac.V5

[<AbstractClass>]
type DacRecord(recordType: int16) =
    do
        if recordType < 0s then
            invalidArg (nameof recordType) "Argument out of range"

    member this.Type = recordType

and an inheriting class in an adjacent file:

namespace Dac.V5

[<AbstractClass>]
type DacReturnRecord(recordType: int16, decodedData: byte seq) =
    inherit DacRecord(recordType)

    let data: byte seq = decodedData

    member this.Data with get() = data and set(v) = data <- v

However, in the inheriting class, the base class appears undefined, and I get an error on the inherit statement.

The files are in the same subdirectory, and are named after the classes they hold.

CodePudding user response:

As mentioned in the comments, you need to order the files so that the base class comes before the inherited one. Once you do this, it should work, except that you need to mark data as mutable:

[<AbstractClass>]
type DacReturnRecord(recordType: int16, decodedData: byte seq) =
    inherit DacRecord(recordType)

    let mutable data: byte seq = decodedData

    member this.Data with get() = data and set(v) = data <- v
  • Related