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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dbcfe2b0a74da57e X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 17 Sep 2007 23:03:19 -0500 From: "Steve" Newsgroups: comp.lang.ada References: <1190039166.449906.15070@g4g2000hsf.googlegroups.com> Subject: Re: Inherited Methods and such Date: Mon, 17 Sep 2007 21:03:45 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 Message-ID: X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 24.20.111.206 X-Trace: sv3-v5SyHkG0+RLLKcwcCg6fc9RQNp0+x4gYiRJC3FXNR4ZAspz5H39asZo2VrNib7UwD7fYI7ia9DZa8nL!SPkqmBT8645MOIyLx4MAPhlM1vzoqcoFyOuA5jMShTudZtcVtfxIJ1bGipuE9Xn1ArOi10SbANln!miwzHKOVHULZ7M4TU8r1I9h1HKkUNw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.35 Xref: g2news2.google.com comp.lang.ada:2005 Date: 2007-09-17T21:03:45-07:00 List-Id: wrote in message news:1190039166.449906.15070@g4g2000hsf.googlegroups.com... > Hi, > [snip] > Is this type of method inheritance supported in ada? If so, > where am I going wrong? > Yes this type of method inheritance is supported in Ada, but you're using the wrong constructs. The Ada equivalent to a C++ class is a tagged type. In C++ you may declare a class: class Base is { public: virtual void Test1(); }; In Ada the equivalent is:: type Base is tagged null record; procedure Test1( obj : Base ); To derive a subclass from Base in C++ you would use: class Derived : public Base { public: virtual void Test1(); }; The Ada equivalent is: type Derived is new Base with null record; procedure Test1( obj : Derived ); In C++ to declare an objects of type Base an Derived and to invoke their Test1 functions you use: Base obj1; Derived obj2; obj1.Test1(); obj2.Test1(); The Ada 95 equivalent is: declare obj1 : Base; obj2 : Derived; begin Test1( obj1 ); Test1( obj2 ); end; Or in Ada 2005 you may use the alternative syntax: declare obj1 : Base; obj2 : Derived; begin obj1.Test1; obj2.Test1; end; The sample code below does some of what your example code was doing, and may be helpful in helping to sort things out. ------------------------------- package Base_Package is type Base_Class is tagged null record; procedure Test1( base : Base_Class ); procedure Test2( base : Base_Class ); end Base_Package; ------------------------------- with Ada.Text_IO; use Ada.Text_IO; package body Base_Package is procedure Test1( base : Base_Class ) is begin Put_Line( "Test1 FROM BASE CLASS"); end Test1; procedure Test2( base : Base_Class ) is begin Put_Line( "Test2 FROM BASE CLASS"); end Test2; end Base_Package; ------------------------------- with Base_Package; use Base_Package; package Base_Subclass_Package is type Base_Subclass is new Base_Class with null record; procedure Test1( base : Base_Subclass ); procedure Test2( base : Base_Subclass ); end Base_Subclass_Package; ------------------------------- with Ada.Text_IO; use Ada.Text_IO; package body Base_Subclass_Package is procedure Test1( base : Base_Subclass ) is begin Put_Line( "Test1 FROM BASE SUBCLASS"); end Test1; procedure Test2( base : Base_Subclass ) is begin Put_Line( "Test2 FROM BASE SUBCLASS"); end Test2; end Base_Subclass_Package; ------------------------------- with Base_Package; use Base_Package; with Base_Subclass_Package; use Base_Subclass_Package; procedure Run_Test is a : Base_Class; b : Base_Subclass; procedure DoIt( base : Base_Class'class ) is begin Test1( base ); end DoIt; begin DoIt( a ); DoIt( b ); end Run_Test; Regards, Steve (The Duck) > Thanks > -- > Shaun Patterson >