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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,1be082612b8c5f2e X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!feed-C.news.volia.net!volia.net!news2.volia.net!feed-A.news.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Dynamically tagged expression not allowed. Why? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Sat, 29 May 2010 20:23:36 +0200 Message-ID: NNTP-Posting-Date: 29 May 2010 20:23:37 CEST NNTP-Posting-Host: aa6740c4.newsspool4.arcor-online.net X-Trace: DXC=R>knllh5@[II7\_^6>c20J4IUK On Sat, 29 May 2010 12:36:33 -0500, Marc A. Criley wrote: > Stripping out a test case, I see that it has nothing to with the C++ > binding per se, but it's an Ada issue that's flummoxing me. Here's the > test code: > > procedure Dyty_Test is > > type Class_Type is tagged limited record > null; > end record; > > function New_Class_Instance return Class_Type'Class; > > Conn : Class_Type := New_Class_Instance; Should Conn be mutable? Otherwise you could use a function instead. > function New_Class_Instance return Class_Type'Class is > begin > -- Just a stub > return New_Class_Instance; Infinite recursion. I suppose it is return X : Class_Type; > end New_Class_Instance; > > The error is on the declaration of "Conn", with the error occurring on > the invocation of the initializing New_Class_Instance function. I'm just > not understanding something here. You are "returning" a class-wide limited object, which is to "initialize" a specific object. A more difficult problem is that to initialize Conn, GNAT wants to know the body of the initializer. -------------------------------------------------------------- Variant 1. Two packages (to have the body): package P is type Class_Type is tagged limited record null; end record; function New_Class_Instance return Class_Type'Class; function New_Class_Object return Class_Type; end P; package P.Instances is Conn : Class_Type := New_Class_Object; end P.Instances; package body P is function New_Class_Object return Class_Type is begin return X : Class_Type; end New_Class_Object; function New_Class_Instance return Class_Type'Class is begin return New_Class_Object; end New_Class_Instance; end P; ---------------------------------------------------------------------------------------------------- Variant 2. Old good Ada initialization (in 80's we knew how to do it right) package P is type Class_Type is tagged limited record null; end record; function New_Class_Instance return Class_Type'Class; Conn : Class_Type; -- It will be OK upon the body elaboration! end P; package body P is procedure Construct (Object : in out Class_Type) is begin null; end Construct; function New_Class_Instance return Class_Type'Class is begin return X : Class_Type do Construct (X); end return; end New_Class_Instance; begin Construct (Conn); -- Fix it now end P; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de