comp.lang.ada
 help / color / mirror / Atom feed
* troubles learning OOP: expected type "Parent.Some_Child", found type Parent'Class
@ 2018-02-12 16:29 Mehdi Saada
  2018-02-12 17:44 ` Jeffrey R. Carter
                   ` (4 more replies)
  0 siblings, 5 replies; 35+ messages in thread
From: Mehdi Saada @ 2018-02-12 16:29 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] 35+ messages in thread

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

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-12 16:29 troubles learning OOP: expected type "Parent.Some_Child", found type Parent'Class Mehdi Saada
2018-02-12 17:44 ` Jeffrey R. Carter
2018-02-12 18:17   ` Mehdi Saada
2018-02-12 18:24     ` Dmitry A. Kazakov
2018-02-12 18:42       ` Simon Wright
2018-02-12 20:25     ` Jeffrey R. Carter
2018-02-12 21:18       ` Mehdi Saada
2018-02-12 22:40         ` Simon Wright
2018-02-12 23:12           ` Mehdi Saada
2018-02-13  8:00         ` Stephen Leake
2018-02-13 17:42         ` Jeffrey R. Carter
2018-02-13 17:56           ` Dmitry A. Kazakov
2018-02-12 21:19       ` Mehdi Saada
2018-02-12 18:40   ` Simon Wright
2018-02-12 21:39 ` Mehdi Saada
2018-02-12 21:43 ` Mehdi Saada
2018-02-12 22:22   ` Mehdi Saada
2018-02-13 17:46     ` Jeffrey R. Carter
2018-02-13 20:19       ` Mehdi Saada
2018-02-13 21:24         ` Bojan Bozovic
2018-02-13 23:03           ` Mehdi Saada
2018-02-13 23:03             ` Mehdi Saada
2018-02-14  7:00               ` Bojan Bozovic
2018-02-14 12:04                 ` Mehdi Saada
2018-02-16 23:40                   ` Mehdi Saada
2018-02-17  1:13                     ` Mehdi Saada
2018-02-13  0:01 ` Mehdi Saada
2018-02-13  0:42   ` Mehdi Saada
2018-02-13  1:32     ` Mehdi Saada
2018-02-13  4:16       ` Bojan Bozovic
2018-02-13 11:28       ` Simon Wright
2018-02-13 12:03         ` Mehdi Saada
2018-02-13 13:25         ` Dmitry A. Kazakov
2018-02-19 18:10 ` Mehdi Saada
2018-02-19 18:16   ` Simon Clubley

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