comp.lang.ada
 help / color / mirror / Atom feed
From: evangeli@cnam.fr (Evangelista Sami)
Subject: pointer on an operator
Date: 18 Mar 2004 06:32:10 -0800
Date: 2004-03-18T06:32:10-08:00	[thread overview]
Message-ID: <5f59677c.0403180632.7c338bf7@posting.google.com> (raw)

hello

i have declared this type :

type bin_op is (plus_op, minus_op, div_op, mod_op, ...);

i want to make a function which takes a bin_op two integers and return
the result of the operation :

function get_bin_op_result(op : bin_op; left, right : integer) return
integer is
begin
   case op is
      when plus_op  => return left + right;
      when minus_op => return left - right;
      ...
   end case;
end;

to avoid this, is there a way to make a function which return an
access to the right operator.like this :

type operator_access is access function(I1, I2 : Integer) return
Integer;
function get_operator(op : in bin_op) is
begin
   case op is
      when plus_op  => return "+"'access;
      when minus_op => return "-"'access;
      ...
   end case;
end;

then the function simply becomes :
function get_bin_op_result(op : bin_op; left, right : integer) return
integer is
begin
   return get_operator(op).all(left, right);
end;

i have tried this but the compilator complains on
"when plus_op  => return "+"'access;" :

expressions.adb:299:17: expected type "Function_Access" defined at
line 296
expressions.adb:299:17: found type access to ""+"" defined at line 29

is there a way to do this?



             reply	other threads:[~2004-03-18 14:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-18 14:32 Evangelista Sami [this message]
2004-03-18 14:58 ` pointer on an operator Georg Bauhaus
replies disabled

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