comp.lang.ada
 help / color / mirror / Atom feed
* How to dynamically dispatch?
@ 1995-03-16  6:36 Dale Stanbrough
  1995-03-17 10:37 ` Samuel Tardieu
  0 siblings, 1 reply; 2+ messages in thread
From: Dale Stanbrough @ 1995-03-16  6:36 UTC (permalink / raw)


I'm currently having problems figuring out how to dispatch
to the appropriate routines for the package (based on an
example in the LRM) below...

package expression is

        type expression is tagged null record;

        type literal is new Expression with
                record
                        value   :integer;
                end record;
        function eval(item:literal) return integer;

        type Expr_ptr is access all Expression'class;

        type binary_operation is new Expression with
                record
                        Left, Right: Expr_ptr;
                end record;

        type addition is new Binary_operation with null record;
        function eval(item:addition) return integer;

        type subtraction is new binary_operation with null record;
        function eval(item:subtraction) return integer;
end;

The body is....

package body expression is

        function eval(item:literal) return integer is
        begin
                return item.value;
        end;

        function eval(item:addition) return integer is
        begin
                return eval(item.left.all) + eval(item.right.all);
        end;

        function eval(item:subtraction) return integer is
        begin
                return eval(item.left.all) - eval(item.right.all);
        end;
end;

...but Gnat just says "invalid parameter list in call" for each
of the eval calls. To me this seems the same the example in
"Introducing Ada9x" in section 2.2.

Any thoughts?

Dale



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

end of thread, other threads:[~1995-03-17 10:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-16  6:36 How to dynamically dispatch? Dale Stanbrough
1995-03-17 10:37 ` Samuel Tardieu

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