HNHacker News
TopNewBestAskShowJobs

bob-ROS

4 karma · joined March 28, 2021

submissionscomments
bob-ROS··on Ada for the C++ and Java Developer [pdf]
Yes, that works.
bob-ROS··on Ada for the C++ and Java Developer [pdf]
I got it working with:

with Ada.Text_IO; use Ada.Text_IO;

procedure Main is

     type Distance is new Float;
     type Area is new Float;

   function "*" (Left, Right : Distance) return Area is
     temp : Distance;
   begin
     temp := Left * Right;
     return Area (temp);
   end "*";

     D1 : Distance := 2.0;
     D2 : Distance := 3.0;
     A  : Area;

  begin
     A  := D1 * D2; -- OK
     Put_Line(A'Image);
 end Main;
Interestingly, it took me several attempts to create this overload, make it a single line return would make it recursive:

   function "*" (Left, Right : Distance) return Area is
   begin
      return Left * Right;
   end "*"; --   ^ Does not work
            --   raised STORAGE_ERROR : stack overflow or erroneous memory access
Also:

   function "*" (Left, Right : Distance) return Area is
   begin
      return Area (Left * Right);
   end "*"; --  ^ Does not work either, compiler gives me "ambiguous operand in conversion"