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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8c49ff480209334c X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Inheritance question... Date: 1997/03/25 Message-ID: #1/1 X-Deja-AN: 228235839 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <33361956.4F30@pacbell.net> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-03-25T00:00:00+00:00 List-Id: Marc Bejerano (mbejeran@pacbell.net) wrote: : I have a package called foo... : package foo is : type bar is tagged private; : type bar1 is new bar with private; : . : . : . : private : type bar is tagged record : v: integer; : end record; : type bar1 is new bar with record : vv: character; : end record; : end foo; : when I try to create a descendent type in my main procedure I get: : "type extension at deeper accessibility level than parent" This one should be in the FAQ... : here's my "simplified" main procedure: : with foo; use foo; : procedure foofoo is : type my_bar is new bar1 with record : s: string(1..128); : end record; : begin : . : . : . : end foofoo; : what am I doing wrong? The declarations inside a procedure are at a deeper "accessibility" level than the declarations outside the procedure. Accessibility level is essentially the same thing as dynamic nesting level. Packages don't increase the accessibility level, but functions, procedures, tasks, and declare-blocks do. When you extend a tagged type, you must do it at the same accessibility level as the parent type. Hence, you must move your type extension into a package, which you "with" from your procedure foofoo. The reason for this limitation is that a copy of an object of your type extension "my_bar" might be created in the heap, and then your procedure foofoo might exit. If you had overridden any primitive operations on the type, those overridings would also be "gone" once foofoo exited. The copy of the "my_bar" object would effectively have dangling references to the primitive operations declared inside foofoo. The simplest rule to remember is never declare a tagged type, including a type extension, inside a function or procedure. Define types at the package level. : TIA, Marc -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA