* Re: generic unit : compilation error ! please help me
[not found] <1140772786.942747.88370@j33g2000cwa.googlegroups.com>
@ 2006-02-24 10:51 ` Stephen Leake
2006-02-24 10:51 ` Dmitry A. Kazakov
1 sibling, 0 replies; 2+ messages in thread
From: Stephen Leake @ 2006-02-24 10:51 UTC (permalink / raw)
nblanpain@hotmail.com writes:
> hello,
> When i compile the following programm, i have the following error on
> function Set_Unit_To_Test of class "child-test_unit.adb" :
> "14 : invalid tagged conversion, not compatible with type T_Child'Class
> defined at child.ads"
> I don't undestand this error : please help me !
>
> ## parent.ads ## :
minor point; please use Ada comments for separators like this, so
gnatchop can handle them.
> generic
> type T_Real is digits <>;
> package Parent is
> type T_Parent is tagged private;
> type T_Parent_Access is access all T_Parent;
> private
> type T_Parent is tagged record
> Real : T_Real;
> end record;
> end Parent;
I have not fully sorted out your problem, because I find the names too
confusing. While it is proper to have similar names like this in a
finished product, they do get in the way of finding structural
problems.
So first, do these steps:
1) Get rid of the subtypes; use the full type names. It will make
things clearer.
2) Name things clearly, without relying on the package name;
Parent_Class_Access_Type, Child_Class_Access_Type.
I think you have too many class-wide access types. In particular, I
think you are trying to store a parent unit test in an object of type
child unit test. The object probably needs to be of type
Parent_Class_Access.
The clearer names will help you sort out what you really want to do.
Once that is clear, you can change the names back to be more
user-friendly.
--
-- Stephe
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: generic unit : compilation error ! please help me
[not found] <1140772786.942747.88370@j33g2000cwa.googlegroups.com>
2006-02-24 10:51 ` generic unit : compilation error ! please help me Stephen Leake
@ 2006-02-24 10:51 ` Dmitry A. Kazakov
1 sibling, 0 replies; 2+ messages in thread
From: Dmitry A. Kazakov @ 2006-02-24 10:51 UTC (permalink / raw)
On 24 Feb 2006 01:19:47 -0800, nblanpain@hotmail.com wrote:
> ## parent.ads ## :
> generic
> type T_Real is digits <>;
> package Parent is
> type T_Parent is tagged private;
> type T_Parent_Access is access all T_Parent;
> private
> type T_Parent is tagged record
> Real : T_Real;
> end record;
> end Parent;
>
> ## child.ads ##
> with Parent;
> generic
> type T_Real is digits <>;
> with package Par is new Parent (T_Real);
> package Child is
> type T_Child is new Par.T_Parent with private;
> type T_Child_Access is access all T_Child;
> private
> type T_Child is new Par.T_Parent with record
> Real2 : T_Real;
> end record;
> end Child;
>
> ## parent-test_unit.ads ##
> generic
> package Parent.Test_Unit is
> subtype T_Unit_To_Test is Parent.T_Parent;
> subtype T_Unit_To_Test_Access is Parent.T_Parent_Access;
> type T_Unit_To_Test_Class_Access is access all T_Unit_To_Test'Class;
> type T_Test_Unit is tagged private;
> type T_Test_Unit_Access is access all T_Test_Unit;
> procedure Set_Unit_To_Test
> (This : in out T_Test_Unit;
> Utt : in T_Unit_To_Test_Class_Access);
> private
> type T_Test_Unit is tagged record
> Unit_To_Test : T_Unit_To_Test_Class_Access;
> end record;
> end Parent.Test_Unit;
>
> ## parent-test_unit.adb ##
> package body Parent.Test_Unit is
> procedure Set_Unit_To_Test
> (This : in out T_Test_Unit;
> Utt : in T_Unit_To_Test_Class_Access) is
> begin
> This.Unit_To_Test := Utt;
> end Set_Unit_To_Test;
> end Parent.Test_Unit;
>
> ## child-test_unit.ads ##
> with Parent.Test_Unit;
> generic
> with package Parent_Test_Unit is new Parent.Test_Unit;
with package Parent_Test_Unit is new Par.Test_Unit;
Parent of Child and Parent of Parent.Test_Unit should be the same beast.
> package Child.Test_Unit is
> subtype T_Unit_To_Test is Child.T_Child;
> subtype T_Unit_To_Test_Access is Child.T_Child_Access;
> type T_Unit_To_Test_Class_Access is access all T_Unit_To_Test'Class;
> type T_Test_Unit is new Parent_Test_Unit.T_Test_Unit with private;
> type T_Test_Unit_Access is access all T_Test_Unit;
> procedure Set_Unit_To_Test
> (This : in out T_Test_Unit;
> Utt : in T_Unit_To_Test_Class_Access);
> private
> type T_Test_Unit is new Parent_Test_Unit.T_Test_Unit with record
> Unit_To_Test2 : T_Unit_To_Test_Class_Access;
> end record;
> end Child.Test_Unit;
>
> ## child-test_unit.adb ##
> package body Child.Test_Unit is
> procedure Set_Unit_To_Test
> (This : in out T_Test_Unit;
> Utt : in T_Unit_To_Test_Class_Access) is
> begin
> Parent_Test_Unit.Set_Unit_To_Test
> (Parent_Test_Unit.T_Test_Unit (This),
> Parent_Test_Unit.T_Unit_To_Test_Class_Access (Utt)); --
> error !!!!!!!
> This.Unit_To_Test2 := Utt;
> end Set_Unit_To_Test;
> end Child.Test_Unit;
P.S. Don't use pointers, generics and Hungarian notation.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-02-24 10:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1140772786.942747.88370@j33g2000cwa.googlegroups.com>
2006-02-24 10:51 ` generic unit : compilation error ! please help me Stephen Leake
2006-02-24 10:51 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox