From: Mart van de Wege <mvdwege@mail.com>
Subject: Single element arrays as function parameters
Date: Fri, 10 Jun 2011 22:11:49 +0200
Date: 2011-06-10T22:11:49+02:00 [thread overview]
Message-ID: <86ei31v43e.fsf@gareth.avalon.lan> (raw)
I have the following function:
function Creature (Name : in String;
Race : in MM_Subtype;
Level : in Positive;
Player : in String)
return Character_Ptr is
C : Character_Ptr;
Temp : Integer;
begin
C := new Player_Character;
C.Creature_Name := To_Unbounded_String(Name);
C.Creature_Type := Humanoid;
C.Creature_Subtype := new MM_Subtype'(Race);
C.Character_Level := Class_Level(Level);
C.Player := To_Unbounded_String(Player);
return C;
end Creature;
It will update the following record:
type Creature is
tagged record
Creature_Name : Unbounded_String;
Creature_Type : MM_Type;
Creature_Subtype : access MM_Subtype;
end record;
(actually, it will update a derived type with a few extra fields, but
that is not important right now).
It works just fine when called like this:
M := Init.Creature( Name => "Duergar",
Creature_Type => Humanoid,
Creature_Subtype => (Dwarf,Psionic) );
But when called like this
M := Init.Creature( Name => "Dwarf",
Creature_Type => Humanoid,
Creature_Subtype => (Dwarf) );
The above call fails to compile:
test_create.adb:11:13: no candidate interpretations match the actuals:
test_create.adb:11:13: missing argument for parameter "Race" in call to "Creature" declared at games-rpg-dnd-creatures.ads:47
test_create.adb:11:13: missing argument for parameter "Level" in call to "Creature" declared at games-rpg-dnd-creatures.ads:44
test_create.adb:13:45: positional aggregate cannot have one component
test_create.adb:13:45: ==> in call to "Creature" at
games-rpg-dnd-creatures.ads:40
If I look at the language documentation, I'm guessing that this is
because a single element array does not get recognised as being of type
MM_Subtype, which is defined as
type MM_Subtype is array(Natural range <>) of Possible_MM_Subtype;
What *is* the best way to store an attribute which may be either a
single enumeration element or a list of enumeration elements?
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
next reply other threads:[~2011-06-10 20:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-10 20:11 Mart van de Wege [this message]
2011-06-10 20:54 ` Single element arrays as function parameters J-P. Rosen
2011-06-10 21:28 ` Mart van de Wege
2011-06-10 21:58 ` Adam Beneschan
2011-06-10 22:24 ` Mart van de Wege
2011-06-11 12:28 ` Peter C. Chapin
2011-06-13 14:49 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox