comp.lang.ada
 help / color / mirror / Atom feed
* problems with generic package
@ 2002-05-29  9:08 user
  2002-05-29 11:21 ` Preben Randhol
  2002-05-29 16:34 ` Stephen Leake
  0 siblings, 2 replies; 3+ messages in thread
From: user @ 2002-05-29  9:08 UTC (permalink / raw)


good morning

i have declared a generic package generic_set with the following 
specification:


generic
    type Element is private;

package Generic_Set is
...
end package;



then in another package i introduced a tagged type with two derived 
types like this:


type node is tagged null record;
type place is new node with record ... end record;
type transition is new node with record ... end record;


how is it possible to declare a new package set over the node type?
this declaration doesn't work :

package nodes_set is new generic_set(element => node'class);

error:

instantiation error
unconstrained subtype in component declaration
actual for "Element" must be a definite subtype


thanks for any help




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

* Re: problems with generic package
  2002-05-29  9:08 problems with generic package user
@ 2002-05-29 11:21 ` Preben Randhol
  2002-05-29 16:34 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Preben Randhol @ 2002-05-29 11:21 UTC (permalink / raw)


On Wed, 29 May 2002 11:08:41 +0200, user@domain.invalid wrote:

1) You use an invalid e-mail address
2) You give no real name
3) You don't even write your name at the end of the post

So why would we want to help you?

Preben



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

* Re: problems with generic package
  2002-05-29  9:08 problems with generic package user
  2002-05-29 11:21 ` Preben Randhol
@ 2002-05-29 16:34 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2002-05-29 16:34 UTC (permalink / raw)


user@domain.invalid writes:

> error:
> 
> instantiation error
> unconstrained subtype in component declaration
> actual for "Element" must be a definite subtype

The rules on "definite" vs "indefinite" vs "unconstrained" can be
confusing. Without your complete code, I can't tell what the correct
solution might be. See section 12.5.1 in the ARM, or the chapter on
generic formal types in your favorite Ada book. 

In this case, the error message is telling you that the actual type
('node') you are providing to match Element has an unconstrained
component, which makes it an indefinite subtype.

Since you define 'node' as:

type node is tagged null record;

this doesn't make much sense. Please provide the actual code you
compiled, and the complete error message.

One way to let a generic formal type accept an unconstrained subtype
is to add an unknown discriminant (ARM 12.5.1 (28), ARM 3.7 (3)):

generic
    type Element (<>) is private;

package Generic_Set is
...
end package;

But that may not be what you want.
> 
> 
> 
> thanks for any help
> 

-- 
-- Stephe



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

end of thread, other threads:[~2002-05-29 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-29  9:08 problems with generic package user
2002-05-29 11:21 ` Preben Randhol
2002-05-29 16:34 ` Stephen Leake

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