From: "Craig Garrett" <cgarrett@siscom.net>
Subject: Please help! Aggregate Object - dynamically allocating the objects inside, doesnt work
Date: 1999/01/09
Date: 1999-01-09T00:00:00+00:00 [thread overview]
Message-ID: <01be3b99$6fe27620$5104fbd1@longslide> (raw)
I need help. I am probably doing something stupid, but here is my
situation:
I have an aggregate object (Ada95) called Time_Manager. Its a tagged
record, and two of its fields are pointers (access types) to different
classes. In a procedure I am calling start that is in the Time_Manager
package, I try to use the new operator to dynamically allocate these fields
and get actual objects in there, not just pointers. Pretty standard right?
Its just aggregate objects - thats all. Anyway, the compiler is choking
on it, where I call the new operator.
Here is the code:
package sim_clock is
.....
type object is Tagged
record
Current_Time : long_float := 0.0;
Last_Time : long_float := 0.0;
Time_Since_Last : long_float := 0.0;
Last_Time_of_Day : Ada.Calendar.Time;
Current_Time_of_Day : Ada.Calendar.Time;
end record;
type object_pointer is access object;
end sim_clock;
package wall_clock is
....
type object is Tagged
record
Current_Time,
Last_Time : Ada.Calendar.Time := Ada.Calendar.Clock;
Time_Since_Last : Duration := 0.0;
end record;
type object_pointer is access object;
end wall_clock;
then the aggregate object, Time_Manager is:
package time_manager is
type object is Tagged
record
Wall_Time : wall_clock.object_pointer;
Sim_Time : sim_clock.object_pointer;
end record;
type object_pointer is access object;
end time_manager;
Ok, then I have a Start procedure in time_manager :
procedure Start(this_time_manager : in out object_pointer) is
begin
this_time_manager.Wall_Time := new wall_clock.object;
this_time_manager.Sim_Time := new sim_clock.object;
end Start;
The compiler is choking on the two "new" lines, this is the error:
time_manager.adb: Error: line 15 col 40 LRM:5.2(4), Type mismatch in
assignment statement, continuing
time_manager.adb: Error: line 16 col 40 LRM:5.2(4), Type mismatch in
assignment statement, continuing
Now, it has always been my understanding that dynamic allocation goes like
this:
You create an access type to some type (integer, record, whatever) and
then declare a variable of that access type.
Then, you call the new operator like this:
<access variable> := new <TYPE>;
so if I have an access type to an integer called int_pointer, then I could:
my_int_pointer : int_pointerr;
begin
my_int_pointer := new INTEGER;
and that would work right? That is what I read in the books, but it doesnt
seem to work with my aggregate objects.
I am at a total loss, I can provide all the code if you want, please help!
- Craig
next reply other threads:[~1999-01-09 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-09 0:00 Craig Garrett [this message]
1999-01-09 0:00 ` Please help! Aggregate Object - dynamically allocating the objects inside, doesnt work David C. Hoos, Sr.
1999-01-09 0:00 ` Craig Garrett
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox