comp.lang.ada
 help / color / mirror / Atom feed
* Access to tagged type parameters
@ 2001-08-17  9:16 Jonathan DeSena
  2001-08-17 16:23 ` David Brown
  2001-08-17 21:45 ` tmoran
  0 siblings, 2 replies; 7+ messages in thread
From: Jonathan DeSena @ 2001-08-17  9:16 UTC (permalink / raw)


According to Cohen's "Ada as a Second Language," which I've been using to 
pick up Ada95 in my spare time:

"All formal parameters belonging to tagged 
types are implicitly declared to be aliased. This allows a subprogram to 
create access values pointing to its tagged formal parameters using the 
'Access attribute ..." (section 12.6.2, page 579 in my version)

This is the ONLY reference to this in the book I can find; there are no 
examples of it's use, though it seems simple enough.  However, no matter 
what I try, I can't seem to get such code to compile using gnat 3.13p on 
Debian/Linux (Intel). I continually get the following error:

non-local pointer cannot point to local object

Here's a code snippet which I've been using as a test case -- it doesn't do 
anything, but I just use it to see if it will compile:
--start test.adb
with Ada.Text_IO;
procedure Test is

   type A_Type is tagged record
      A1:Integer; --just to fill the record with something
      A2:Integer;
   end record;
   type A_Access_type is access all A_Type'Class;

   procedure A_Test (B:in out A_Type'Class) is
      B_Access: A_Access_Type;
   begin
      B_Access:=B'Access;
      Ada.Text_IO.Put_Line("Done.");
   end A_Test;

   C:A_Type;
begin
   A_Test(C);
end Test;
--end test.adb

Does anyone know if this works as advertised? Or maybe I am 
misunderstanding the statement in the book? Anyone have a similar example 
to the above that DOES work?

I'd like to be able to use access values to a tagged type in a subprogram 
which has the type itself as a parameter rather than an access type. That 
way, when the tagged type is inherited, the subprograms will go with it. 
Subprograms which only have access types to the tagged type do not get 
inhereted by the derived type it seems.

Thanks in advance.

jtd



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-08-20 14:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-17  9:16 Access to tagged type parameters Jonathan DeSena
2001-08-17 16:23 ` David Brown
2001-08-17 19:26   ` Ted Dennison
2001-08-17 13:55     ` Jonathan DeSena
2001-08-17 21:51       ` Ted Dennison
2001-08-20 14:03         ` Jonathan DeSena
2001-08-17 21:45 ` tmoran

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