comp.lang.ada
 help / color / mirror / Atom feed
From: Mehdi Saada <00120260a@gmail.com>
Subject: troubles learning POO: expected type "Parent.Some_Child", found type Parent'Class
Date: Mon, 12 Feb 2018 07:33:45 -0800 (PST)
Date: 2018-02-12T07:33:45-08:00	[thread overview]
Message-ID: <595e044c-e71b-401e-902b-ab70d2730ee1@googlegroups.com> (raw)

I'm learning POO.
I have trouble, indeed. Please look at this:

if GET_ELEM (TOKEN_COURANT) = '(' then VALIDE;
-->
expected type "T_Token_Operateur" defined
Found type T_TOKEN'Class

The definitions:
 type T_TOKEN is abstract null record ;
   type T_Vect_Token is array (Positive range <>) of access T_Token'Class;

type T_Token_Operateur is new T_Token with
      record
      L_Operateur : T_Operateur;
   end record;

function Get_Elem (Token : in T_Token_Operateur) return T_Operateur is (Token.L_Operateur);
function TOKEN_COURANT return T_TOKEN'Class is
begin
	 INDEX := INDEX + 1;
	 return V (INDEX - 1).all;
end;
where V : in T_Vect_Token;

What I do: I declare a T_Token'Class as a local variable. Then, according to the content of the array (V), I do things like this:
when '+' | '-' | '*' | '/'
     => V_LOCAL(INDEX_VECT).all := TO_TOKEN(T_OPERATEUR'Value(STRING'(1 => ELEMENT)));
with a different qualified expression for each sub-classes of Token.

             reply	other threads:[~2018-02-12 15:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 15:33 Mehdi Saada [this message]
2018-02-12 16:35 ` troubles learning POO: expected type "Parent.Some_Child", found type Parent'Class Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox