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

* Re: troubles learning POO: expected type "Parent.Some_Child", found type Parent'Class
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Wright @ 2018-02-12 16:35 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> 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

This is because you've declared

> function Get_Elem (Token : in T_Token_Operateur) return T_Operateur
>    is (Token.L_Operateur);

You don't say what T_Operateur is, though it appears to be a Character.

If you declare

> type T_TOKEN is abstract null record ;
   function Get_Elem (Token : in T_Token) return String is abstract;

then Get_Elem is primitive, and you could declare

   function Get_Elem (Token : in T_Token_Operateur) return String;

and you'd get dispatching on the Token parameter when you supply a
T_Token'Class. But that that requires that the Token parameter is in
T_Token'Class and that the other parameters, if any, and the return type
match exactly.

Which gives you a problem since you've stored L_Operateur as a
T_Operateur. You could return (String'(1 => Token.L_Operateur)).

(I'm assuming that other kinds of token could be longer than 1
character).


^ 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