comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@arcor.de>
Subject: Re: how to import a package
Date: Tue, 12 Dec 2006 11:56:34 +0100
Date: 2006-12-12T11:55:44+01:00	[thread overview]
Message-ID: <1165920993.21859.15.camel@localhost> (raw)
In-Reply-To: <1165893584.829025.235440@l12g2000cwl.googlegroups.com>

On Mon, 2006-12-11 at 19:19 -0800, markww wrote:


> I'm wondering still if it's possible to have a data member in the
> package definition that serve as my start and end nodes.

As Jeffrey and Stuart have explained, you are still led astray
by a misconception: A C++ struct/class here corresponds to an Ada
type, not to an Ada package. Although you need a package to
associate the "methods" with the tagged type, all data members
must become the record components in the type definition.

C++: From a struct or class, you create objects.
Ada: From a type, you create objects.

C++: Operations of a type are declared within the struct/class
Ada: Operations of a type are declared after the type within
     a surrounding package.

Compare the following definitions:

namespace Geo
{
  struct Any
  {
    int x, y;
    virtual void move(int a, int b) = 0;
  };

  struct Point : public Any
  {
    virtual void move(int a, int b);
  };

  struct Circle : public Any
  {
    int r;
    virtual void move(int a, int b);
  };
}


package Geo is

   type Any is abstract tagged record
      x, y: Integer;
      -- data members of any geometric object
   end record;

   procedure move(thing: in out Any; a, b: Integer) is abstract;
   -- abstract method of Any



   type Point is new Any with record
      null;
         -- no additional data members
   end record;

   --overriding
   procedure move(thing: in out Point; a, b: Integer);



   type Circle is new Any with record
      r: Integer;
      -- Circle objects with radius
   end record;

   --overriding
   procedure move(thing: in out Circle; a, b: Integer);

end Geo;

HTH,
-- Georg





  parent reply	other threads:[~2006-12-12 10:56 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06  2:14 how to import a package markww
2006-12-06  3:06 ` Adam Beneschan
2006-12-06  3:34   ` markww
2006-12-06  9:18     ` Simon Wright
2006-12-06 19:47 ` Jeffrey R. Carter
2006-12-06 23:56   ` markww
2006-12-07  1:18     ` Björn Persson
2006-12-07  1:26     ` Brian May
2006-12-07  4:14       ` markww
2006-12-07  4:40         ` Brian May
2006-12-07  9:32           ` Stuart
2006-12-07 11:21             ` Jean-Pierre Rosen
2006-12-11  6:16               ` markww
2006-12-11  6:50                 ` markww
2006-12-11  9:40                   ` Georg Bauhaus
2006-12-11 14:19                     ` markww
2006-12-11 15:03                       ` Dmitry A. Kazakov
2006-12-11 16:22                       ` Adam Beneschan
2006-12-11 20:28                       ` Jeffrey R. Carter
2006-12-12  3:19                         ` markww
2006-12-12  3:31                           ` Jeffrey R. Carter
2006-12-12  9:03                           ` Stuart
2006-12-12 10:56                           ` Georg Bauhaus [this message]
2006-12-11  7:00                 ` Simon Wright
2006-12-07  4:06     ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox