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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,154942e4f1d1b8e9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Dynamically tagged expression required Date: Fri, 09 Dec 2005 10:09:04 +0100 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: <2852224.m2vuDFxfOX@linux1.krischik.com> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1134119343 1514 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Red Hat/1.7.12-1.1.3.2.SL3 X-Accept-Language: en-us, en In-Reply-To: <2852224.m2vuDFxfOX@linux1.krischik.com> Xref: g2news1.google.com comp.lang.ada:6791 Date: 2005-12-09T10:09:04+01:00 List-Id: Martin Krischik wrote: >> A : Shape; >> B : Shape'Class := A; -- (1) >> C : Triangle := (SideLen => 7); >>begin >> >> A := C; -- (2) >> B := C; -- (3) >> >>end Hello; >>Why is (1) allowed? > > because it is an initialization. OK, so that explains why it's possible to use Shape'Class as a parameter in subroutine. Every time the subroutine is called, the parameter is *initialized* with the value, and therefore it can be different for each call: procedure Draw(S : Shape'Class); T : Triangle; R : Rectangle; and later: Draw(T); -- S initialized with T Draw(R); -- S initialized with R Right? >>Why is (3) not allowed? > > because it is an assignment. And this is where I want to dig deeper. > http://en.wikibooks.org/wiki/Ada_Programming/Object_Orientation This page says: "The Class type is a real data type. You can declare variables of the class-wide type, assign values to them [...]" "Assign values to them" is a problem here. As the subject of my original post says (and what compiler told me), "dynamically tagged expression required". What can I provide as a dynamically tagged expression? It looks like some ShapeClassPtr.all is OK there, except that I get the CONSTRAINT_ERROR, if the new value has a different tag. This observation agrees with what Dmitry said - the tag of the class-wide object cannot be changed. What other dynamically tagged expression can be provided as a right-hand side of the (default) assignment to the object of class-wide type? Is this useful in practice? Regards, -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/