Why is the base only possible in private members?

I have some understanding of the differences between private members and bindings bindings . This may help me clear up my doubts about understanding why something like this is not possible.

type B () =
    inherit A ()

    let doSomething () =
        base.CallToA ()   

      

Should partially constructed objects or some leaks be prevented during construction?

+2


source to share


1 answer


The keyword is base

really needed to call the base class's virtual method implementation. This is the only case you need to base

, because you cannot call a method using an instance this

(as this is the case for overriding in the current class).

You are partially correct that the compiler wants to prevent access to partially constructed objects. However, this is done by requiring you to explicitly state that you want to be able to refer to the current instance inside the constructor using as this

:



type B () as this =
  inherit A ()

  let doSomething () =
    this.CallToA ()   

      

The ID this

is just a name - similar to member declarations, so you can use a different name there.

+4


source







All Articles