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.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, TO_NO_BRKTS_PCNT autolearn=no autolearn_force=no version=3.4.4 X-Received: by 10.13.241.65 with SMTP id a62mr26826262ywf.5.1441725038979; Tue, 08 Sep 2015 08:10:38 -0700 (PDT) X-Received: by 10.182.112.234 with SMTP id it10mr104796obb.13.1441725038939; Tue, 08 Sep 2015 08:10:38 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!z77no1621908qge.1!news-out.google.com!nt1ni4509igb.0!nntp.google.com!kq10no1824308igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 8 Sep 2015 08:10:38 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.210.217.198; posting-account=ZsBWjAoAAACn5uHwNWb19e60TrEtWbAD NNTP-Posting-Host: 155.210.217.198 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <625c79d2-f5ed-4cd4-80ea-ea310e381017@googlegroups.com> Subject: working with diferent instances of the same generic interface From: Aitor Alcrudo Sangros Injection-Date: Tue, 08 Sep 2015 15:10:38 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:27743 Date: 2015-09-08T08:10:38-07:00 List-Id: Hi, my google-fu can't find how to do this. I think it should be doable but I'm not 100% sure. I'm thankful if anyone helps. I have a generic interface some of my tagged records instance, similar to: package Intro is type Data_type is interface; generic type Readable_Data is abstract new Data_type with private; package Readable is type Readable_Element is interface; type Readable_Element_Access is access all Readable_Element'Class ; function Get_Values (this : Readable_Element ) return Readable_Data'Class is abstract; end Readable; type state is (OK,KO); generic with package Readable_Reporting is new Readable(<>); use Readable_Reporting ; package Reporting is type Reporting_Element is interface and Readable_Element ; type Reporting_Element_Access is access all Reporting_Element'Class; function Report (This :Reporting_Element ) return state is Abstract; overriding function Get_Values (this : Reporting_Element ) return Readable_Data'Class is abstract; end Reporting; end Intro; This has worked with no problem. I instance it like this SomeData is new Data_type with record a :float; end record; package Readable is new Intro.Readable( readable_data =>SomeData); package Reporting is new Intro.Reporting(Readable); type Element_type_A is new Readable.Readable_Element and Reporting.Reporting_Element with record data :float; end record; type Element_type_A_Access is access all Element_type_A 'Class; Now, I have something like this package Reporter is package Readable_basic is new Intro.Readable(Data_type ); package Reporting_basic is new Intro.Reporting(Readable); use Reporting; type manager is tagged private; procedure Add_Element( This : in out manager ; Element : in Reporting_Element_Access ); private package Element_Vector is new Ada.Containers.Vectors (Natural,Reporting_Element_Access ); use Element_Vector ; type manager is tagged record Element_List : Element_Vector.Vector; end record; end Reporter ; this compiles. Now I try to use it elsewhere procedure try is man :manager ; elm1 : Element_type_A_Access ; elm2 : Element_type_B_Access ; begin man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm1) ); man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm2) ); end; This compiles, but produces a runtime exception with invalid interface conversion. Is there any way to get this to work?.