comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <mcNOSPAM@mckae.com>
Subject: Re: Dynamically tagged expression not allowed. Why?
Date: Sat, 05 Jun 2010 13:47:26 -0500
Date: 2010-06-05T13:47:26-05:00	[thread overview]
Message-ID: <6a0a$4c0a9bce$433a4eca$18947@API-DIGITAL.COM> (raw)
In-Reply-To: <hu45hk$3g8$1@munin.nbi.dk>

On 06/01/2010 06:36 PM, Randy Brukardt wrote:
> "Marc A. Criley"<mcNOSPAM@mckae.com>  wrote in message
> news:c2ead$4c0150a0$4ca4a823$11809@API-DIGITAL.COM...
> ...
>> 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;
>
> This is illegal because the function returns a class-wide object and you are
> assigning it into an object of a specific type. You have to explicitly use a
> type conversion here:
>
>      Conn : Class_Type := Class_Type (New_Class_Instance);
>
> to specify that you want to truncate the returned object, or make the object
> classwide:
>
>     Conn : Class_Type'Class := New_Class_Instance;
>
> But notice that while both of these are legal, they'll both raise
> Program_Error because an access-before-elaboration error (the body of
> New_Class_Instance hasn't been elaborated at the point of this call).

Actually, stripping out the C++ interface pragmas was probably a bad 
idea on my part. (Though the thread *was* educational :-)

I thought that to create an instance of the C++ class I had to invoke 
the New_Class_Instance function myself, from which arose this issue. 
Turns out I don't. GNAT's handling of the C++ pragmas does it all for me 
automagically.

The documentation on creation an Ada binding to C++ is somewhat...terse 
when it comes to describing the mechanics of what is going on "under the 
hood", from whence came my misunderstanding.

So this part is all better now, I can step in and verify that my 
constructors are being executed. I'm having other problems, but that's 
just the usual banging the head against the wall stuff.

Marc A. Criley
www.mckae.com



      parent reply	other threads:[~2010-06-05 18:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-29 17:36 Dynamically tagged expression not allowed. Why? Marc A. Criley
2010-05-29 18:23 ` Dmitry A. Kazakov
2010-06-03  2:37   ` Yannick Duchêne (Hibou57)
2010-06-03  7:48     ` Dmitry A. Kazakov
2010-06-01 23:36 ` Randy Brukardt
2010-06-03  2:36   ` Yannick Duchêne (Hibou57)
2010-06-03  7:57     ` Dmitry A. Kazakov
2010-06-03  8:21       ` Yannick Duchêne (Hibou57)
2010-06-03 16:03     ` Adam Beneschan
2010-06-05 18:47   ` Marc A. Criley [this message]
replies disabled

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