comp.lang.ada
 help / color / mirror / Atom feed
* Another question on class constructor
@ 2011-11-08  2:27 Rego, P.
  2011-11-08  4:32 ` Randy Brukardt
  0 siblings, 1 reply; 6+ messages in thread
From: Rego, P. @ 2011-11-08  2:27 UTC (permalink / raw)


I have a class defined as:

   type Test_Class is tagged limited
      record
         Info    : Integer;
         Value   : Float;
         Primary : Primary_Task (Test_Class'Access);
      end record;

I need build a one-step constructor for my class in the form

   function Construct (T : access Test_Class) return Test_Class_Ptr is
   begin
      return new Test_Class'(Info => T.Info + 1,
                             Value => 0.0,
                             Primary => [WHAT I WANNA KNOW]);
   end Construct;

Currently my code is:

-- test_pkg.ads
package Test_Pkg is
   type Test_Class;
   type Test_Class_Ptr is access all Test_Class;

   task type Primary_Task (This_Test : access Test_Class) is
      pragma Storage_Size (1000);
   end Primary_Task;

   type Test_Class is tagged limited
      record
         Info    : Integer;
         Value   : Float;
         Primary : Primary_Task (Test_Class'Access);
      end record;

   function Construct (T : access Test_Class) return Test_Class_Ptr;
end Test_Pkg;

-- test_pkg.adb
with Text_IO; use Text_IO;
package body Test_Pkg is
   [...]

   function Construct (T : access Test_Class) return Test_Class_Ptr is
      T_Ptr : constant Test_Class_Ptr := new Test_Class;
   begin
      T_Ptr.Info := T.Info + 1;
      T_Ptr.Value := 0.0;
      return T_Ptr;
   end Construct;
end Test_Pkg;

So, how can I code it? What should I put in Primary => [...] code? Should I change the definition of Primary : Primary_Task (Test_Class'Access); in Test_Class definition? Thanks.



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

end of thread, other threads:[~2011-11-10  1:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-08  2:27 Another question on class constructor Rego, P.
2011-11-08  4:32 ` Randy Brukardt
2011-11-09  0:40   ` Rego, P.
2011-11-09  1:08     ` Rego, P.
2011-11-09  8:30     ` Simon Wright
2011-11-10  1:25       ` Rego, P.

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