floating point - Ada: float instantiation from another package -


I am trying to create a new float type with 6 digit precision. But it seems that I am not able to use it. Here is the code with the package MyFloat_IO.ads

  with Ada.Text_IO; Package is MyFloat_IO IF MYFloat IIS 6 6 DZET 0.0..Float'Last; Package MyFloat_IO New ADA. Text_IO.Float_IO (MyFloat); Finally MyFloat_IO;  

and main code:

  with Ada.Text_IO; With MyFloat_IO; Use MYFloat_IO; With Ada Annumerics; Process exam is 2x: MyFloat: = 3.5; Y: Permanent: = Ada.Numerics.Pi; Z: MyFlat; BEGIN - Main Event Z: = X * Y; MyFloat_IO.Put (Zed); Ada.Text_IO.New_Line; END Test 2;  

I get an error message on the compilation:

  14. BEGIN - Main Event 15. Z: = X * Y; 16. MyFlot_io.put (Zed); | & Gt; & Gt; & Gt; "Put" has not been declared in "MyFlot_io" 17. ADA Test_IO.New_Line; 18. End test 2;  

What am I doing?

Thank you very much ...


Update: New code according to TED suggestions:

  1. Package MyFloat_I0.ads :

      with Ada.Text_IO; Package MyFloat_I0 ISI Type Instance 6 DGIT 6 Range 0.0. Float'Last; Package is MyFloat New Ada.Text_IO.Float_IO (example); Finally MyFloat_I0;  
  2. and the main code:

      with Ada.Text_IO; With MyFloat_I0; Use MyFloat_I0; With Ada Annumerics; The process exam is 2 x: Example: = 3.5; Y: Permanent: = Ada.Numerics.Pi; Z: Example; BEGIN - Main Event Z: = X * Y; MyFloat.Instance.Put (Zed); Ada.Text_IO.New_Line; END Test 2;  

I get the following compilation:

  MyFloat.Instance.Put (Z); | & Gt; & Gt; & Gt; "Instance" has not been declared in "Mimelhot"  

Whatever you do wrong It is that you have given a package named MyFloat_IO (received from ADA test_io.flot_io) inside another package gave the name Miflot_IO as it was declared to you You must call to get it:

  MyFloat_IO.MyFloat_IO.Put (Z);  

I am sure that it is possible to get a package from a generic as a compilation unit. However, you might consider rename the package MyFloat , such as example , and your IO package IO in this way, using it People like I type for the IO package and call MyFloat.Instance for MyFloat.IO .

(answer to update)

I can see from the code you posted, I have to confuse you completely. This is what I had (warning: not compiled).

  Package is MyFlot Type Example Issue 6 is the level of 0.0 0.0 Float'Last; - 'Package Io is the new Eda. Test_io.flat_io (example); The end of the mifle; In other words, the package is named  MyFloat , type name is  example , and the IO package is named . IO is given . When the phone is called from the outside of the package, then that type is  MyFloat.Instance , and keep it is regular  MyFloat.IO.Put . 

Note that if you are using Gnat, you will have to rename the source file upon changing the package name.


Comments