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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1a1baf807a7fe9e2,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!r37g2000prr.googlegroups.com!not-for-mail From: AndreiK Newsgroups: comp.lang.ada Subject: Inheritance problem! Date: Thu, 18 Dec 2008 07:14:59 -0800 (PST) Organization: http://groups.google.com Message-ID: <9e295547-60dc-4e5e-ac2d-3534ea65ad01@r37g2000prr.googlegroups.com> NNTP-Posting-Host: 193.40.240.135 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1229613300 3857 127.0.0.1 (18 Dec 2008 15:15:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 18 Dec 2008 15:15:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r37g2000prr.googlegroups.com; posting-host=193.40.240.135; posting-account=kfQcmwoAAAAImQIpF8z0neulU3uSEwPV User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:4007 Date: 2008-12-18T07:14:59-08:00 List-Id: Hello everybody! I am quite new in Ada programming and I am trying to write simple (at the moment) OO program, but I have a problem with inheritance of the private type. I am using the GNAT+GPS (2008) and learning Ada by John Barnes "Ada 2005". The idea of the program is next: we have tagged private types Vector and Matrix. The Matrix inheritances all components and functions from Vector. Difference only in constructor: Mat is for Matrix and Vec is for Vector. In the test program the errors occures when I try to call inherited function, in the example it is Cell(...) and if I try to use function Put(This: Vect.Vector'Class). I don't understand where the mistake is? Thanks everybody for a help! The code of the test program: ---------------------------------------- -- test.adb ---------------------------------------- with Ada.Text_IO; with Vectors.Matrices; procedure test is package TIO renames Ada.Text_IO; package FIO is new Ada.Text_IO.Float_IO(Float); package Vect is new Vectors(Float); --use Vect; package Matr is new Vect.Matrices;-- use Matr; M1: Matr.Matrix := Matr.Mat(4, 3, 1.0); V1: Vect.Vector := Vect.Vec(3, 2.0); -- Procedure, which intended to print out the Vector or Matrix objects. -- procedure Put(This: in Vect.Vector'Class) is begin TIO.New_Line; TIO.New_Line; for J in 0 .. This.Size(0)-1 loop TIO.Put("|"); for K in 0 .. This.Size(1)-1 loop FIO.Put( Item => This.Cell(J, K), Fore => 2, Aft => 3, Exp => 3); TIO.Put(" "); end loop; TIO.Put("|"); TIO.New_Line; end loop; null; end; begin FIO.Put(M1.Cell(0,0)); -- test.adb:37:14: error: -- no selector "Cell" for private type "Matrix" -- defined at vectors-matrices.ads:6, instance at line 10 Put(M1); -- test.adb:39:08: error: expected type "Vector'class" -- defined at vectors.ads:12, instance at line 9 -- test.adb:39:08: error: found private type "Matrix" -- defined at vectors-matrices.ads:6, instance at line 10 -- test.adb:39:08: error: ==> in call to "Put" at line 14 Put(V1); -- No Errors for Vector V1. FIO.Put(V1.Cell(0,0)); -- No Errors for Vector V1. TIO.New_Line; end test; ---------------------------------------- -- vectors.ads ---------------------------------------- generic type Real is digits <>; package Vectors is pragma Preelaborate; subtype Dim_Type is Natural; type Sizes_Arr is array(Integer range <>) of Dim_Type; -- -- The type is private -- type Vector is tagged private; pragma Preelaborable_Initialization (Vector); -- -- Vec - the constructor of the entity of type Vector. -- function Vec(Elem_Num: Dim_Type; Fill_by_Value: Real'Base := 0.0) return Vector; -- -- Function Cell returns the value of the element at position Index -- of the object of the type Vector. -- function Cell( This : in Vector; Row_Index: in Natural; Col_Index: in Natural ) return Real'Base; function Row_Len(This: in Vector) return Natural; function Col_Len(This: in Vector) return Natural; -- -- Function Size returns the array (1D) of the dimension's sizes of the object -- of the type Vector. -- function Size(This: in Vector) return Sizes_Arr; private type Elements_Array is array (Natural range <>) of Real'Base; type Elements_Access is not null access Elements_Array; type Vector is tagged record Elements_ac : Elements_Access; Count : Natural := 0; Sizes : Sizes_Arr(0..1); Transposed : Boolean := False; Busy : Natural := 0; end record; end Vectors; ---------------------------------------- -- vectors-matrices.ads ---------------------------------------- generic package Vectors.Matrices is pragma Preelaborate; type Matrix is tagged private; pragma Preelaborable_Initialization (Matrix); function Mat(Row_Num,Col_Num: in Dim_Type; Fill_by_Value: Real'Base := 0.0) return Matrix; private type Matrix is new Vector with null record; end Vectors.Matrices;