* Error message: expect valid subtype mark to instantiate ....
@ 2003-12-24 13:13 gilmour
2003-12-24 17:04 ` Robert A Duff
0 siblings, 1 reply; 2+ messages in thread
From: gilmour @ 2003-12-24 13:13 UTC (permalink / raw)
Compiling 'Client_Account_List.ads' following message appears:
client_account_list.ads:4:47: expect valid subtype mark to instantiate "T"
Somebody please advise, what is wrong ???
These are the code samples:
-- Class_List.ads
with Ada.Finalization, Unchecked_Deallocation;
use Ada.Finalization;
generic
type T is private; --Any type
package Class_List is
type List is new Controlled with private;
procedure Initialize (
The : in out List );
procedure Initialize (
The : in out List;
Data : in T );
procedure Finalize (
The : in out List );
procedure Adjust (
The : in out List );
function "=" (
F : in List;
S : in List )
return Boolean;
private
type Node; --Tentative declaration
type P_Node is access all Node; --Pointer to Node
type Node is
record
Prev : P_Node; --Previous Node
Item : T; --The physical item
Next : P_Node; --Next Node
end record;
type List is new Controlled with
record
First_Node : aliased P_Node := null; --First item in list
Last_Node : aliased P_Node := null; --First item in list
end record;
end Class_List;
-- Class_List.adb
package body Class_List is
procedure Dispose_Node is
new Unchecked_Deallocation( Node, P_Node );
procedure Release_Storage (
The : in out List ) is
Cur : P_Node := The.First_Node; --Pointer to curr node
Tmp : P_Node; --Node to dispose
begin
while Cur /= null loop --For each item in list
Tmp := Cur; --Item to dispose
Cur := Cur.Next; --Next node
Dispose_Node( Tmp ); --Dispose of item
end loop;
end Release_Storage;
procedure Initialize (
The : in out List ) is
begin
The.First_Node := null; --Empty list
The.Last_Node := null; --Empty list
end Initialize;
procedure Initialize (
The : in out List;
Data : in T ) is
begin
The.First_Node := new Node'(null, Data, null);
The.Last_Node := The.First_Node;
end Initialize;
procedure Finalize (
The : in out List ) is
begin
if The.First_Node /= null then
Release_Storage( The );
The.First_Node := null;
end if;
end Finalize;
procedure Adjust (
The : in out List ) is
Cur : P_Node := The.First_Node; --Original list
Lst : P_Node := null; --Last created node
Prv : P_Node := null; --Previously created node
Fst : P_Node := null; --The first node
begin
while Cur /= null loop
Lst := new Node'( Prv, Cur.Item, null );
if Fst = null then
Fst := Lst;
end if;
if Prv /= null then
Prv.Next := Lst;
end if;
Prv := Lst;
Cur := Cur.Next; --Next node
end loop;
The.First_Node := Fst; --Update
The.Last_Node := Lst;
end Adjust;
function "=" (
F : in List;
S : in List )
return Boolean is
F_Node : P_Node := F.First_Node; --First list
S_Node : P_Node := S.First_Node; --Second list
begin
while F_Node /= null and S_Node /= null loop
if F_Node.Item /= S_Node.Item then
return False; --Different items
end if;
F_Node := F_Node.Next;
S_Node := S_Node.Next;
end loop;
return F_Node = S_Node; --Both NULL if equal
end "=";
end Class_List;
-- Class_Client_Acount.ads
with Gnat.Sockets; use Gnat.Sockets;
package Class_Client_Account is type Client_Account is tagged private;
procedure Set_Id(The : in out Client_Account; Id : String);
procedure Set_Channel(The : in out Client_Account; Channel : Stream_Access);
function Get_Id(The : in Client_Account) return String;
function Get_Channel(The : in Client_Account) return Stream_Access;
private
type Client_Account is tagged
record
Id : String(1 .. 8);
Channel : Stream_Access;
end record;
end Class_Client_Account;
-- Class_Client_Acount.adb
package body Class_Client_Account is
procedure Set_Id(The : in out Client_Account; Id : String) is
begin
The.Id:=Id;
end;
procedure Set_Channel(The : in out Client_Account; Channel : Stream_Access) is
begin
The.Channel:=Channel;
end;
function Get_Id(The : in Client_Account) return String is
begin
return The.Id;
end Get_Id;
function Get_Channel(The : in Client_Account) return Stream_Access is
begin
return The.Channel;
end Get_Channel;
end Class_Client_Account;
-- Client_Account_List.ads
with Class_List;
with Class_Client_Account;
pragma Elaborate_All(Class_List);
package Client_Account_List is new Class_List(Class_Client_Account);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Error message: expect valid subtype mark to instantiate ....
2003-12-24 13:13 Error message: expect valid subtype mark to instantiate gilmour
@ 2003-12-24 17:04 ` Robert A Duff
0 siblings, 0 replies; 2+ messages in thread
From: Robert A Duff @ 2003-12-24 17:04 UTC (permalink / raw)
gilmour@banda.lv (gilmour) writes:
> Compiling 'Client_Account_List.ads' following message appears:
> client_account_list.ads:4:47: expect valid subtype mark to instantiate "T"
> Somebody please advise, what is wrong ???
You gave it the name of a package (Class_Client_Account).
It wants the name of a type (to match the generic formal
parameter T).
By the way, I suggest you format your code properly, so it will be
easier to read. For example:
generic
type T is private; --Any type
package Class_List is
type List is new Controlled with private;
...
"generic" and "package" should be lined up, since they're part of the
same piece of syntax. That way, you can see that T is a generic formal
parameter of Class_List, and List is inside Class_List, and so forth.
- Bob
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-12-24 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-24 13:13 Error message: expect valid subtype mark to instantiate gilmour
2003-12-24 17:04 ` Robert A Duff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox