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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5f0f4bfb0467bb19 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.0.170 with SMTP id 10mr688876pbf.2.1320805509182; Tue, 08 Nov 2011 18:25:09 -0800 (PST) Path: h5ni14823pba.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: "Rego, P." Newsgroups: comp.lang.ada Subject: Re: Constructors with multiple inheritance Date: Tue, 8 Nov 2011 18:24:53 -0800 (PST) Organization: http://groups.google.com Message-ID: <21605158.153.1320805494018.JavaMail.geo-discussion-forums@yqiu15> References: <11513972.2788.1317325228383.JavaMail.geo-discussion-forums@yqnv12> <1rj1mmkvwud1d.dzqoy4jhdfca$.dlg@40tude.net> <4976045.4489.1317352313370.JavaMail.geo-discussion-forums@yqjw35> <2pu3h5hqltxi$.ze4yrf1f2y8z.dlg@40tude.net> <23774546.1654.1317391464047.JavaMail.geo-discussion-forums@yqnk41> <1gnrks1djlaok.1k0r5f8z9ylfx.dlg@40tude.net> Reply-To: comp.lang.ada@googlegroups.com NNTP-Posting-Host: 200.148.121.196 Mime-Version: 1.0 X-Trace: posting.google.com 1320805509 24160 127.0.0.1 (9 Nov 2011 02:25:09 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 Nov 2011 02:25:09 +0000 (UTC) Cc: mailbox@dmitry-kazakov.de In-Reply-To: <1gnrks1djlaok.1k0r5f8z9ylfx.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=200.148.121.196; posting-account=TRgI1QoAAABSsYi-ox3Pi6N-JEKKU0cu User-Agent: G2/1.0 X-Google-Web-Client: true Xref: news1.google.com comp.lang.ada:18875 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-08T18:24:53-08:00 List-Id: > function Construct (Object_Reference : access Parent_Class) > return Parent_Class_Ptr; I tried this approach in the following code, but it still complains about the null object. -- test_pkg.ads package Test_Pkg is type Test_Class is tagged; type Test_Class_Ptr is access all Test_Class; function Construct (T : access Test_Class) return Test_Class_Ptr; task type Primary_Task (This : not null access Test_Class); type Test_Class is tagged limited record Info : Integer := 0; Value : Float; Primary : Primary_Task (Test_Class'Access); end record; end Test_Pkg; -- test_pkg.adb with Text_IO; use Text_IO; package body Test_Pkg is task body Primary_Task is begin loop Put_Line (Integer'Image (This.Info) & "__"); delay 0.2; end loop; end Primary_Task; 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; -- test_pkg_user.adb with Test_Pkg; with Text_IO; use Text_IO; procedure Test_Pkg_User is Test_Obj : Test_Pkg.Test_Class_Ptr; begin Test_Obj := Test_Obj.Construct; Put_Line ("Value = "&Integer'Image (Test_Obj.Info)); end Test_Pkg_User; The message I get is the following: c:\tst>gnatmake test_pkg_user.adb gcc -c test_pkg_rev623_user.adb test_pkg_user.adb:12:16: warning: null value not allowed here test_pkg_user.adb:12:16: warning: "Constraint_Error" will be raised at run time gcc -c test_pkg.adb gnatbind -x test_pkg_user.ali gnatlink test_pkg_user.ali What am I still doing wrong? Thanks again. Note: Sure if I put in test_pkg_user.adb Test_Obj : Test_Pkg.Test_Class_Ptr := new Test_Pkg.Test_Class; it returns me a build with no warning, but I think this way I allocate memory twice to the pointer (one in the call new Test_Pkg.Test_Class and the other in the construct method execution), right?