Menu:

Design and Sell Merchandise Online for Free

Dot notation for tagged types

Using the code from the interface types tutorial, we can now use the dot notation provided by Ada 2005. This allows the programmer to use the dot for tagged types which will be familiar from other programming languages like C++.

C++ code
class Dragster : public Vehicle, public Parachute {
    bool GearUp();
    // etc.
};

Dragster D;
bool     Result = D.GearUp();

The usual way of referencing a primitive for a tagged type is to either use the package that contains it or to reference it including the package's name:

Ada95 code
with Dragster;

procedure Test is

  D      : Dragster.Dragster_Type;
  Result : Boolean;

begin

  Result := Dragster.Gear_Up(D);
  
end Test;

So, we can transform our code to use the new notation and we still don't have to use the package!

Ada 2005 code
with Dragster;

procedure Test is

  D      : Dragster.Dragster_Type;
  Result : Boolean;

begin

  -- D is passed as the "Self" parameter to Gear_Up.
  Result := D.Gear_Up;
  
end Test;

I have placed a full example into a compressed text file which can be built with GNAT using the following commands:

Bash code
$ gunzip dot_notation.ada.gz
$ gnatchop -cw -gnat05 dot_notation.ada
$ gnatmake -gnat05 test.adb

Other Ada 2005 compilers will differ.

Download dot_notation.ada.gz

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
Security Code: *