Ada: Understanding private types and understanding packaging

前端 未结 1 1561
余生分开走
余生分开走 2021-01-22 11:46

I am trying to learn how to use private declarations in Ada and also to understand packaging. I have tried to keep my codes as short as possible.

We start with the main

相关标签:
1条回答
  • 2021-01-22 12:26

    why do not I have to use the methods set_Horz(A) and set_Vert(A) prior to issuing the command

    Because you're setting the fields of your private record by executing:

    Rectangular_Form.Vector_Basis_r (A => Theta, D => Basis_r);

    (Review the implementation of Vector_Basis_r.)

    -- EXPANDED Answer

    When you declare the Basis_r variable in your Test_Rectangular_Form procedure, the memory for that "Rectangular" variable is allocated. At this point the Horz and Vert fields in the private type are present, but unset (they could contain anything).

    When you call Rectangular_Form.Vector_Basis_r, its implementation sets the values of those private fields. Maybe this is what's confusing you: the body of the package in which a private type is declared has direct access to those fields. This is exactly the aspect that Vector_Basis_r is exploiting when setting their values (as well as Set_Vert and Set_Horz).

    0 讨论(0)
提交回复
热议问题