comp.lang.ada
 help / color / mirror / Atom feed
* class wide object in generic package
@ 2002-06-10  7:38 Thomas Maier-Komor
  2002-06-10 12:28 ` Craig Carey
  2002-06-10 13:00 ` Stephen Leake
  0 siblings, 2 replies; 10+ messages in thread
From: Thomas Maier-Komor @ 2002-06-10  7:38 UTC (permalink / raw)


Hi everybody,

I am getting this error message when compiling the
code at the end of the message:

generic_pac.adb:7:26: class-wide argument not allowed here
generic_pac.adb:7:26: "eval" is not a primitive operation of "Object"


my question is:
first: is it possible to declare a procedure in the
generic part so that it will be a primitive operation of
Object?
second: why isn't a class-wide argument not allowed
in this place?


Thanks,


Tom



generic_pac.ads:
generic
	type Object is abstract tagged private;
	type Pointer is access all Object'class;
	with procedure eval(o : in out Object);
	
package generic_pac is
	type gen is record
		p : Pointer;
	end record;

	procedure use_it(g : in out gen);
	
end generic_pac;
===========================================
generic_pac.adb:
with Ada.Text_IO; use Ada.Text_IO;

package body generic_pac is
	procedure use_it(g : in out gen) is
	begin
		Put_Line("generic_pac.use_it");
		eval(g.p.all);
	end use_it;
end generic_pac;

-- 
________________________________________________________________________
Dipl.-Ing. Thomas Maier-Komor                   http://www.rcs.ei.tum.de
Institute for Real-Time Computer Systems (RCS)      fon +49-89-289-23578
Technische Universitaet Muenchen, D-80290 Muenchen  fax +49-89-289-23555




^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: class wide object in generic package
@ 2002-06-10 11:07 Grein, Christoph
  0 siblings, 0 replies; 10+ messages in thread
From: Grein, Christoph @ 2002-06-10 11:07 UTC (permalink / raw)


> first: is it possible to declare a procedure in the
> generic part so that it will be a primitive operation of
> Object?
> second: why isn't a class-wide argument not allowed
> in this place?
>
> generic_pac.ads:
> generic
> 	type Object is abstract tagged private;
> 	type Pointer is access all Object'class;
> 	with procedure eval(o : in out Object);

You can instantiate with any procedure that matches the profile, so the worst is 
assumed and Eval is not a primitive operation.

> 	
> package generic_pac is
> 	type gen is record
> 		p : Pointer;
> 	end record;
> 
> 	procedure use_it(g : in out gen);
> 	
> end generic_pac;
> ===========================================
> generic_pac.adb:
> with Ada.Text_IO; use Ada.Text_IO;
> 
> package body generic_pac is
> 	procedure use_it(g : in out gen) is
> 	begin
> 		Put_Line("generic_pac.use_it");
> 		eval(g.p.all);

Since Pointer is classwide, this is a dispatching call, but Eval is not 
primitive, so can't be used in a dispatching call.


> 	end use_it;
> end generic_pac;



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

end of thread, other threads:[~2002-06-13 14:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-10  7:38 class wide object in generic package Thomas Maier-Komor
2002-06-10 12:28 ` Craig Carey
2002-06-10 13:14   ` Thomas Maier-Komor
2002-06-10 13:00 ` Stephen Leake
2002-06-10 13:25   ` Thomas Maier-Komor
2002-06-11 20:57   ` Ehud Lamm
2002-06-12 17:33     ` Stephen Leake
2002-06-13  1:58       ` Robert A Duff
2002-06-13 14:07         ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2002-06-10 11:07 Grein, Christoph

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