Function Overload in Gnu Pascal ? 
Author Message
 Function Overload in Gnu Pascal ?

Hello,

I want to have a procedure named

procedure test(var x);

where x can be integer or real. In C++ I would overload the parameters
with

test (int x) {...}
test (double x) {...}

How could this be done in GNU Pascal?

Ciao
       Thomas
---------------------------------------------------------
     Thomas{*filter*}el - Friedhofstr. 11 - 35043 Marburg

---------------------------------------------------------



Fri, 26 May 2000 03:00:00 GMT  
 Function Overload in Gnu Pascal ?

Quote:

> I want to have a procedure named

> procedure test(var x);

> where x can be integer or real. In C++ I would overload the parameters
> with

> test (int x) {...}
> test (double x) {...}

> How could this be done in GNU Pascal?

While adding this feature is planned for the near future,
this currently cannot be done in GNU Pascal.  Sorry.

To work around, you have some possibilities:

  * Write two functions with different names.

  * Use operators instead of functions.  Operator overloading
    already *does* work with GNU Pascal.

  * Pass it as an untyped parameter and pass the type
    information as a separate parameter:

       Procedure Test ( Var X; TypeOfX: Char );

       Var
         XInt: Integer absolute X;
         XReal: Real absolute X;

       begin (* Test *)
         case TypeOfX of
           'i': begin
                  (* Do something with XInt *)
                end (* 'i' *);
           'r': begin
                  (* Do something with XReal *)
                end (* 'r' *);
         end (* case *);
       end (* Test *);

  * Use objects which come along with type information and
    virtual methods.

(* BTW, FPK Pascal has function overloading. *)

Hope this helps,

    Peter

 Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer

 maintainer GNU Pascal [971001] - http://home.pages.de/~gnu-pascal/ [971005]
PGP: AC6C 9445 BE28 A496 0ECC E912 4725 8275  FIGHT SPAM: http://maps.vix.com/



Sat, 27 May 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. function pointer problem in gnu pascal

2. Overloading functions??

3. function overloading

4. Is operator overloading possible in Turbo Pascal ?

5. overloading operators in object pascal?

6. HELP Plse: Pascal equivalent of C++ Overloading

7. Turbo Pascal to GNU Pascal

8. Turbo Pascal for Windows and Round function and randomize function

9. GNU Pascal 2.1 released

10. Full-featured debugger, and pretty-printer, for GNU Pascal (gpc)

11. Freepascal vs GNU-Pascal

12. intalling gnu pascal - help

 

 
Powered by phpBB® Forum Software