comp.lang.ada
 help / color / mirror / Atom feed
* troubles learning POO: expected type "Parent.Some_Child", found type Parent'Class
@ 2018-02-12 15:33 Mehdi Saada
  2018-02-12 16:35 ` Simon Wright
  0 siblings, 1 reply; 2+ messages in thread
From: Mehdi Saada @ 2018-02-12 15:33 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-12 16:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-12 15:33 troubles learning POO: expected type "Parent.Some_Child", found type Parent'Class Mehdi Saada
2018-02-12 16:35 ` Simon Wright

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