From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,659d432f799655b2,start X-Google-Attributes: gid103376,public From: "Craig Garrett" Subject: Please help! Aggregate Object - dynamically allocating the objects inside, doesnt work Date: 1999/01/09 Message-ID: <01be3b99$6fe27620$5104fbd1@longslide>#1/1 X-Deja-AN: 430468703 X-Complaints-To: support@newshosting.com X-Trace: news.siscom.net 915862823 209.251.4.81 (Sat, 09 Jan 1999 01:20:23 EDT) Organization: Newshosting NNTP-Posting-Date: Sat, 09 Jan 1999 01:20:23 EDT Newsgroups: comp.lang.ada Date: 1999-01-09T00:00:00+00:00 List-Id: 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: := new ; 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