comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: new/free of abstract types
Date: 1 Apr 2003 07:13:36 -0800
Date: 2003-04-01T15:13:36+00:00	[thread overview]
Message-ID: <1ec946d1.0304010637.440383a6@posting.google.com> (raw)
In-Reply-To: 3e894e2b$1@news.wineasy.se

"Frank" <franjoe@frisurf.no> wrote in message news:<3e894e2b$1@news.wineasy.se>...
> >
> It is just that it looks as if I want to initialise the new object with the
> values from the parameter one.

It wasn't clear from your original example whether you wanted to
initialize the newly allocated object from the subprogram parameter.

If may be the case that you only need the tag of the object, and not
the object itself.  You could introduce a level of indirection using a
factory method:

  type T is abstract tagged null record;

  type T_Class_Access is access all T'Class;

  function New_T (Dummy : T) return T_Class_Access is abstract;

Each type that derives from T can then override New_T, to return a
newly allocated object of that same type, e.g.

   type NT is new T with null record;

   function New_T (Dummy : NT) return T_Class_Access is
   begin
      return new NT;  --ignore Dummy object
   end;

 
> As you may notice I have the parameter as "out" mode. This prototyping gives
> me the impression that someting is sent in to
> the subprogram still (tag perhaps?). Is it a problem for me to use only
> "out" in this parameter or should I use "in out"?

Use out if you're definately going to assign to the parameter.  
Use inout if you're only going to conditionally assign to the
parameter.



      reply	other threads:[~2003-04-01 15:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-31  7:41 new/free of abstract types Frank
2003-03-31 15:59 ` Matthew Heaney
2003-04-01  8:30   ` Frank
2003-04-01 15:13     ` Matthew Heaney [this message]
replies disabled

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